#archived-shaders
1 messages Β· Page 12 of 1
I tried multiplying the colors like (i think) you would in Blender but you can't connect those nodes so I'm kind of lost
Nevermind! I needed to use Sample Gradient instead of Gradient
Sample Gradient with that image as your Time, yeah
Would you happen to know why the default unity cube works well with this but the ProBuilder cube doesn't?
I was assuming it would be the opposite..
The default unity cube has its UVs laid out all 6 faces stacked
the probuilder cube likely doesnt
ok yeah, manually overlapping the UV's worked
Im trying to fix distortions that occur because of my projection method
I have the base UV, and then a rhomboid derived from that base UV that has directions mapped to that area of the cube
but I can't figure out what those vectors should be to fix the distortion
I keep getting weird shit like this that doesnt fix it
input coordinates creating and placing the rhomboid on the correct face of the cube
trying (and failing) to map the correct directions that I need to distort the UV to remove the existing distortions
the above makes this, but this doesnt fix the distortion
and I dont know how to make it fix the distortion
I could use some help because I am unable to proceed with this
diagram of what im trying to do
make it not stretched
hi I'm having a problem in my clean up game when I fast draw a straight line the line is broken but when I slow draw a straight line it works fine
https://codeshare.io/ZJBKOz here is the script
can someone point out whats the problem
That's normal: your mouse moves a big distance in 1 frame when you move it quickly. So you only get to draw a few pixels.
Not sure how it's related to shaders though...π€
Sorry I thought it's related to shaders cause I use shader graph. Thank you for the info though
I will try to convert it to input touch
That's not gonna help. You need to understand that the game does not run infinite times per a unit of time. If you want a continuous line regardless of mouse speed and frame rate, you'll need to calculate the direction of the mouse movement and set all the pixels between the previous and the current position.
Oh Thanks for the heads up
Hey, can someone help me ? I'm trying to replicate the clouds from sable (see picture below) i already have a toon shader a post process outline and a basic procedural skybox with some tweaks. I'd like to add the clouds in the skybox in the shader, but i have no idea how to achieve the shape of theses clouds :/
Hi guys i was trying to make some stencil shaders from and old tutorial but in URP. im really new to shader graph and can't figure out how to copy them over ( i just included what i put in the shaders otherwise they are default)
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader
{
Tags { "RenderType"="Opaque" }
LOD 200
Stencil {
Ref 1
Comp equal
}
and
Shader "Custom/Stencil Mask"
{
Properties
{
_Color ("Color", Color) = (1,1,1,1)
_MainTex ("Albedo (RGB)", 2D) = "white" {}
_Glossiness ("Smoothness", Range(0,1)) = 0.5
_Metallic ("Metallic", Range(0,1)) = 0.0
}
SubShader
{
Tags { "RenderType"="Opaque" "Queue"="Geometry-100"}
ColorMask 0
ZWrite off
LOD 200
Stencil{
Ref 1
Pass replace
}
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
Hello everyone, I'm having a little bit of problem I want my pattern to glide, but it doesnt looks like it does,, what am I doing wrong?
Well to move, I just need a very small animation
It's like Delta time isnt working
Why would it move? Your tiling stays constant(well, almost)
You don't have any value that increases over time.
Delta time is around the same value every frame(considering you have stable performance)
how can I fix this,
the outline supposed to be like the rocks on the left hand side
Man, shader is just too alien to me π₯²
Pretty sure that happens due to the object gets scaled down or up... at least not the standard 1
Hey,
I've got a problem with my shader, for some reason it gives me an error message and breaks my scene.
kr Denis
Is there a method ApplyMeshModification?@regal ferry
For some reason my shaders are all of a sudden different in game than in editor
does anyone know what could cause this?
I literally haven touched them in like a month
All I can find online is people that having trouble with water shaders
cant find anything like this anywhere
you need to scale it along that axis, probably by sqrt(3)/2 or something. Assuming your UVs are something like UV.r = dot(position, normalize(1,0,1)), UV.g = dot(position, normalize(-1,1,1)); you can get the new basis vectors as i.r = dot(normal, normalize(1,0,1)), i.g = dot(normal, normalize(-1,1,1)) (then normalize i), and j = cross(i, (0,0,1)). Finally, we can say the scaled UVs are (mult * i * dot(UV, i) + j * dot(UV, j)), where mult is our scaling factor which you could derive from geometry and probably has a sqrt(3)
(basically, it should generate the basis vectors in UV that are now along and perpendicular to the diagonals of the cube, transform the UVs into that basis, scale along the diagonal axis, then transform back)
the main difference looks to be shadows
wdym
look at the grass
its swaying like 20x more in game view
this just started happening today
Maybe related to batching
and I havent touched the shader in literally a month
wdym?
Are the objects marked as static?
That would mean they are statically batched too. It combines the meshes into one, which is likely changing the scale of "object space"
ohh
didnt know it did all that
thanks
I was very confused on how it would magically change from editor to game view
not really, its just texture parameter and sample textures 2D and 2 branches
nothing else
If that isnt possible, looks like im going to have to make a shader and apply it on all objects
Can you share the shader code?
i upgraded my project and re imported the shader, now its working
probably the shader was done in another version
Hi, how do I get the offset property to work? Im using the Dissolve shader that is included in the "Unity Particle Pack" asset https://assetstore.unity.com/packages/essentials/tutorial-projects/unity-particle-pack-127325. Currently when I change the offset property nothing happens! I guess I need to add it in the shader somewhere but im very new to shaders so I dont know where to add it. Any help would be greatly appreciated!
Can i use a normal texture sample in an unlit graph?
im using cel-shading so im calculating my own lighting
Should be able to
That makes it more complicated π
Somewhere in your light calculations you should be taking the surface normal into account. That's where the normal map sample should come into play
Is CalculateLights a default node?
its a subgraph
ah
Instead of the normal vector you should sample the normal map I guess
Or maybe multiply them? Not entirely sure
Try using just the normal map first
neither worked, tried adding, multiplying and just plugging the sample straight in
Isn't there a special node for normal map sampling?π€
I dont think so?
Hmmm
Did it have any effect at all?
Also, did you do it for both of the normal vector nodes? You have 2
i put it on the top one now, and it works
though when its completely in shadow, the surface is smooth, which i dont particularly want
Well, that makes sense. There's no light to apply to the bumpiness.
An additional light source from different angle might be needed for that. Pretty sure that's normal for default shaders too.
let me check again with the default shader
default shader, in shadow it is still visable
Hmm
perhaps it's because of the "saturate node"
that clamps the negative value to 0
try remapping the value instead: (v + 1) / 2
There's a remap node
https://docs.unity3d.com/Packages/com.unity.shadergraph@15.0/manual/Remap-Node.html
you'll need to say that again, but so a noob can understand
replace saturate with remap?
basically, your value is between -1 and 1. But saturate clamps it to 0-1
Hello, I was wondering what I could do to take a float4 input (rgba), and change each individual value (I just thought of using a function, but I'm curious if there is any other way). Thank you very much for your time.
split it into channels and do whatever you want with them.
no, in needs to be -1 to 1, out 0 to 1. And remove the saturate one.
you can add sky light as (dot(up, normal) + 1)*sky brightness*sky color
Ah yeah, that might be useful too. Not sure if it's used in the standard shaders though.
I don't do shaders very much, i just followed a tutorial and now tweaking it for my usecase
they probably do something more sophisticated with baking the skymap brightness as a function of normal or something but it's going to be pretty similar anyway
remapping makes it very bright most of the time, but still in shadow its pretty much smooth
is that for the diffuse lighting?
In the standard shader with real time lights? Not sure about that. With baked lights, maybe yeah.
hmmm
yea, want the full graph with the additions from dlich?
real time lights they do specular and diffuse and those are pretty easy to do manually; i was meaning ambient lighting
Try without multiplying the vertex normal
that makes light not affect it at all
Also change the "Space" to object.
in the sample?
Yes. And you didn't apply the same changes to the bottom route
Both saturate and normal vector are still there
I'll change those now
yea that looks alot better! though is there a way to clamp the max amount of light it recieves?
this isnt great
For diffuse lighting, you want
diffuseColor * sunColor * sunBrightness * saturate(dot(normal, sunDirection))
For specular highlights,
specularColor * sunColor * sunBrightness * saturate(dot(normal, sunDirection)) * pow(dot(reflect(normalize(viewDirection), normal), sunDirection), <something large like 50>) * fresnel(<power to taste>)
For diffuse ambient lighting,
diffuseColor * ambientColor * ambientBrightness * 0.5 * (1 + dot(normal, up))
Then just add them all together
this is shader graph, not hlsl
Yeah, maybe it was not the saturate's fault. but the bottom route not using the normal map...
Perhaps it's so bright due to the remapπ€
lemme test again with saturate
all the functions are in shader graph, you just need to implement it
just a matter of copying if you have the surface normal
nah its still mega bright with both saturate / remap
can I use something like UnityEngine.Color.RGBToHSV in a .hlsl file for a shader?
No. Shader is not using c# and doesn't have access to unity api.
might be able to write a custom function that does that though.π€·ββοΈ
Then try clamping somewhere before applying the lights to the albedo
Why would you want to do it in the shader anyway?
Hello, i downloaded model with textures from mixamo, and just extracted textures, but hair of characters looks like this, i tried do transparent rendering mode, tried alpha channel, and don't understand how to fix that, can you explain please?
because my pen colors get HSV input, and then I pass over that hsv input oh wait I can just take HSV input from the method and turn it into RGB and store an RGB value
oh well
Doing it on the shader side, you do it once per pixel drawn. That's a huge waste.
potentially millions of times
While there probably won't be any tangible difference, it's still quite a waste.
Try using alpha clipping/cutout.
where i can find that settings?
On the material.
thank you
You can also try "fade" rendering mode instead of "transparent"
I don't believe you can combine a world space normal vector with a tangent space normal map like that
Not totally confident what the correct process is but probably will have to convert them to same space first, then combine using normal blend
yes, its much better, thank you
where i should use glossiness texture? I rad that specular map and glossines map is almost the same, but my downloaded model already have specular map, so where then i should put glossiness?
Did I implement this correctly?
I must have done it wrong because the noise no longer tiles across the faces
Hmm... Did both come with the model?
@kind juniper yes, model call Sophie from mixamo
I didnt do that dot product thing you said to get my UVs, I just used a rotate about axis node to aim position at it and then take only two of its values. It produces less distortion in the texture than your dot product version does
Not sure then. Maybe it's just so that it can be used with different workflows.
yours from the side vs mine from the side
made a shader sub graph that handles diffuse lighting from sun and sky, specular reflection from the sun, and skybox reflection:
Oh sorry I didn't mean the cube UVs, I meant your UVs
I think that's equivalent; you're projecting the positions into that same diagonal 2D basis
Oh okay ill try passing in my UV π
its sorta kinda almost working, but the seams are pretty visible
the faces do look way less stretched though
let me try your uvs instead of mine
it does stretch the face on the faces to remove the distortion
but doing so also destroys the tiling
im starting to think what I want just isnt possible
hm wait
I might have been looking at the wrong side of the cube
Ah no even from the right side, it still breaks the tiling
it does exactly what I wanted, which turns out to not be the answer to my proble
XY all the way down
the strethching isnt that bad, maybe I can hide it with some clever use of the noise
https://answers.unity.com/questions/1837941/shadergraph-how-do-i-get-an-objects-rotation-value.html
Is there a way to get the objects current rotation in the scene in Shadergraph?
This thread is all that turns up when you google it
Unity is the ultimate game development platform. Use Unity to build high-quality 3D and 2D games, deploy them across mobile, desktop, VR/AR, consoles or the Web, and connect with loyal and enthusiastic players and customers.
and this thread doesnt answer it
XY problem
I need to use world space coordinates for a look
but I need the world space coordinates to rotate to the object spaces's current rotation
hmm maybe I dont need it π€
If the scaling is equal in all directions, I think the object to world (direction) node acting on a unit vector would act like the rotation (if you normalize afterwards)
Hello hello! Is there any way to have Complex Lit from URP render with the deferred lightning?
It always falls back to forward, and in a scene with some lights you notice the pop in of lights appearing, like it would happen on the forward lightning π¦
how can I change this so that instead of sliding forward/backward on that axis, it squishes the sides?
so that the faces that arenot the face thats moving , instead of just panning, they squish, keeping their current exterior edge
XY Im trying to simulate refraction between the interior and exterior face of the cube
I tried using a Refract node but it didnt work, results were not what I wanted
I have a physical resin cube in front of me IRL and when looking straight through it, the back face looks to be about 1/2 of the way of the actual size, and the side faces are that length but squished
getting all kinds of strange results
but not getting any closer to 'the back face of the cube appears closer and the sides are squished'
example of wwhat I mean sorta, except this one is monotone, its not a set of UV coordinates
and I cant figure out how to get UV coordinates out of it instead of a monotone black to white
I have no comprehension of any of this
it just does what it does
For UV coordinates you'd need code that calculates perspective
This one only measures distance between the bounds of a box, sure it looks like it has perspective but there's no information for that
Can someone help me shader graph or shader code. I have no idea how it works. I want to clip off 6 sides of an object like a box and any part of the mesh that is out of that cube area would not be rendered.
so you need to find out if the piexel that you want to render is outside of the box and if it is set the alpha to 0
I figured if it was like normal code I could pass xyz and size and anything outside of that box or sphere I could set alpha to zero but I have literally no idea how to do HLSL but I can do c#.
I would prefer to write the HLSL so maybe I could understand a bit more.
here is a example for having just one clipping plane
https://www.ronja-tutorials.com/post/021-plane-clipping/
a box is just 6 planes combined
Summary Another cool effect is to make the surface disappear when itβs beyond a certain plane.
To follow this tutorial, itβs best to know how surface shaders work - you can find a tutorial how they work here.
Define Plane We start by creating a new C# script which will define the plane we use later and pass it to the shader. It has a material as...
Unity does not like float4
?
what do you mean by that
do you get an error?
I'm trying to set a plane property
From the example shader I just added a line
_Color is the default code that unity generated... I added _Plane and it does not like it being a float4
_Plane("Plane", Vector) = (0, 0, 0, 0)
float4 would be the type in the HLSL portion. Shaderlab uses Vector instead
https://docs.unity3d.com/Manual/SL-Properties.html
Okay looks like it's working so far
Okay not what I was going for
Umbrella shader
Put that on the asset store
Is there a better way to do this with vectors?
float n = 0.4;
distance = abs(IN.worldPos.x - dir.x);
clip(-(distance - n));
distance = abs(IN.worldPos.y - dir.y);
clip(-(distance - n));
distance = abs(IN.worldPos.z - dir.z);
clip(-(distance - n));```
So I made what I expected to be an edge glow shader in ShaderGraph. Now it works fine for sphers, but not for cubes or planes. I'm hoping someone could elaborate as to what I did wrong.
It works if the object's normal is continuous (though you'll get areas of different edge thickness). But when the entire surface has one normal, it's either all lit up or all dull
Hmm... I see. Back to the drawing board I guess
Tbh from geometry alone I don't think it can be done for any arbitrary mesh.
Well I specifically want to do it for planes
Can you just use the UV of the plane?
With the caveat that the plane would be of any shape
ah
Basically I'm trying to implement an xcom like movement outline
So I'm generating the mesh of the appropriate shape
Idk if there's any way for a pixel near the outside of the plane to know it's near the outside
And I'd like to have it's edges have an nice emission glow
Hmmmm
I mean surely there has to be right?
There's plenty of stuff like toon outline shaders
I guess I just gotta go look for that
And how they do it
Toon shaders for 3D objects work by using the normals of the mesh but they won't work for a plane
You could just have it offset the object in a few different directions and paint those offsetted copies to be emissive
Im looking into getting some basic water in my scene (more than just a tinted transparent plane), but so far every single tutorial is all about shadergraph... is Shadergraph that essential to learn in Unity? If so, why isn't it build in?
ah okay Ill try to get view or camera in there π€
Shadergraph isn't essential but it's much more accessible than writing code and can do most of the same things, so a lot of people like to use it
So as a beginner-coder I dont have much choice other than shadergraph to get some basic water on par with some RTS Map builders from 10 years ago? >_>
you can definitely write a shader yourself
It is included if you use the newer render pipelines URP or HDRP
(or a newer editor which has Shader Graph ported for built-in render pipeline, albeit without all the features)
The built-in render pipeline isn't actively being developed anymore afaik
if you can get the position on the plane where it hits, you can get UVs from that
https://alexanderameye.github.io/notes/rendering-outlines/
https://bgolus.medium.com/the-quest-for-very-wide-outlines-ba82ed442cd9
for instance, taking the component of position with the largest absolute value, discarding it, and turning the other two into a Vector2
Oh this is helpful. Yeah, I landed on trying to implement a sobel algo node to see if I can use it to get the edge values
What does taking the component refer to in this context? Component of the largest absolute value is what? I assume discard and take the other two is a Split into a vec2?
max(abs(position.x), max(abs(position.y), abs(position.z)))
Will this lead me towards the end goal of internal refraction making the internal opposite side appear closer? Or is this solving my Y but not my real X?
Im trying to achieve this - how from the in face it looks like the backface is much closer than it is, and the side gets squished
I have lots of methods that get me the back face UVs
but not any to then distort them
I think i would calculate the refracted ray direction, calculate where it lands on the cube, and then go from there
If you've got the position where the ray lands you have everything, really
front and back visualized - I dont actually normally add them together like that
Ahh yes you see, I have everything except for the knowledge/skill to know what to do with the things I have π€
I think there's a refract node?
And "glow" is almost universally a post-processing effect (research bloom), but you can use an emission channel if you want it to contribute to some lighting calcs.
There is, I have it, but everything ive tried to pass in doesnt return the expected value I want
it only takes in a direction and the surface normal
but all I have is two sets of UVs
and I tried putting the min both ways, no dice
Direction is the view direction
I've gotten this part before figured out, but now I only have one single place to pass in another value
and I have two sets of Uvs, I cant pass in both
If you can calculate the UVs as a function of position on the surface of the cube, you can take the fragment position and the refracted ray, jump along it to where it intersects the next face of the cube, and then get the position, and from there get the UVs again
I know you have been helping me a lot lately so I feel like a let down when I say I have absolutely no idea how to do any of that
give me a second to try to understand it
this is the positions of ray in and ray out
but neither takes into account the view direction,which is the thing firing rays
Is the second one not refracted?
the second one is inside out
easier to see when its set to Lit
these are the UVs that need to get distorted as if they are being refracted
How does it work? Maybe you could scavenge it and pass in a different view direction to get the refracted version (if it uses the view direction inside. If not, that would also be interesting)
this is what I have, but I have a real dice on my desk, it should be sort of the opposite of this
Here's how it works
view direction is used
"direction" that is passed in is just 2 or -2, its not actually direction
Excellent, so just make a copy and instead of view direction, pass in the new refracted ray, and if all goes well then it should work
Like this?
Yeah, I figured I can at least get started with with having something being outputted on the shader front and then I can fiddle with the specifics of the post processing after that.
end result is wacky atm
yes but you put in position where it wants surface normal i think
or should I pass in the inside out version and then use it AGAIN on the inside out version?
interesting result
???
what should be plugged in here
Im not understanding
the object space normal vector
interesting, that seems to completely negate whatever it does
the result is identical to if I had passed in a position object space to the cube map at the very end
nothing happens at all if I play with the index of refraction value
Does it work if you set both refractive indices to 1?
They're already set to 1
that is the result of 1
But if you just bypass the refract node with the view direction, does it go back to working?
here is the shader if you want to look yourself, it seems more productive since Im a blind ape trying to do anything
Im unclear what you mean by working in this context
it was never working by my definition of working
Does it show the interior of the cube?
Yes
Since that is what it was before in the subgraph
yeah just one of those 'am I going crazy' checks
Yeah fair point
speaking of crazy - this is my refract
in case maybe I made some super error here thats breaking everything
but to my knowledge thats standard
That seems fine, it's a built-in function after all
yeah
if the two refractive indices are both the same it should just return the view direction so idk why it's acting up. Maybe try negating the view direction going into the refract?
the indexes are just a division
iunno if thats what you expect it to be
yeah that makes sense
tryin this now
Uhhhh so Negating it doesnt do anything
hmm
what if you negte the value coming out of the refract?
or in this case, remove the negate because it already was
yes
without the exit negate (and with not a negated input) it does this wild thing
without exit negate but negating the input view direction, it looks the same as it would if I had skipped the refract entirely like before
changing the IOR values just make the above look even more messed up
are both values 1?
:OOO
they were both 1
negated input and not negating output produces the refraction expected
ayy amazing!
It looks just like the dice on my desk when I move it around
for some reason, the normals look weird along a specific world axis, on specific sides of the mesh. i'm trying to make a triplanar shader. i've been stuck on this problem for hours. the shader works with the default cube / sphere in Unity, but not this specific mesh.
this is smoothness = 0
better example of it working without all the colors interfering
https://cdn.discordapp.com/attachments/996979168304697384/1019764581830238298/neato43.gif
that looks really good :)
I couldnt have solved it without your help, do you want the final node graph for it?
sure, why not
Im getting very close to being feature complete on all these shaders and putting it all together into one GPU melting final product
I'm setting a shader on material at runtime and I have a property on the shader that needs to be set. How do I set the property?
Also my gameobject has these properties, that's how I get the shader in the script. Do I need to create a new shader instance for every object?
I guess each object generated in the script could share a property and I could change the shader to make calculations from that.
I have a feeling this might be a Unity bug, but I'm getting this issue specifically in the complied output of the shader
Any thoughts?
All the googling I've been doing seem to be leading to completely different anwsers
Does it go away if you use the output?
Nope
Also
I just figured it out
Typo in the name
for custom funciton
an hour of trouble shooting
uggh
And ofc I figure it out the moment after I ask for help -_-
That's why we call it help.
It happens a lot, if I'm having trouble when I go through the process of explaining the issue I get a better understanding and often solve it.
looks clean to me.
Maybe the shadergraph itself its ignoring uv's and generating them unless i specifically tell it to use the mesh uv's
Nope. I've tried using the UV's and it's still not working
I've tried quads and traingles in blender, I've tried tris and keep quads import settings in unity. It makes no difference, all the same result. In the shader I've tried UV0, UV1
I figured it out I think...
Yup it's working now. I was using the Tiling and Offset nodes Tiling x and y values to scale the texture size, rather than scaling the texture itself. I was effectively ruining the UVs by tiling them rather than the texture. Big whoopsie
And I just realized why sobel approach won't work
Relies on camera perspective
Meaning it won't correctly wrap around if hidden behind geometry
Out of all the programming tasks I had this week
I never imagined that it's "just make an outline for a procedural plane" that would be my absolute timesink -_-
Okay how do I make it look like stuff? It just looks like...crap. Like vertex color or something.
Can someone help please how to convert a game object to HDRP textures? When I click on convert all built-in materials nothing happens, when I click 2nd option then it says I need to select a material
Okays that's easy but it all has the same light.
It seems like you're using a custom shader on these objects(Autodesk Interactive). Unity doesn't know how to convert them(the materials), so you'll have to do it manually.
Custom shader? How to select default shader?
Select one of the standard unity shaders in the material.
Now instead of all pink it's all gray
I changed to HDRP/Lit
Yep. You'll need to assign all the textures and parameters manually.
okay, thanks, maybe I'll look for other asset ready for HDRP
Thanks again @kind juniper I've found one model and just only one model free on asset store that converted into HDRP without issue 
Actually you're helping me for a 2nd time
insane!
A couple of days ago I had other issue with a script and you were helpful as well
I don't understand how to get vertex color working. The previous image I posted worked because if fall back to another shader because mine failed to compile.
void vert(inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input, o);
o.vertColor = v.color;
}
void surf (Input IN, inout SurfaceOutputStandard o) {
float3 position = IN.worldPos - _Center.xyz;
float n = _Center.w;
clip(n - abs(position.x));
clip(n - abs(position.y));
clip(n - abs(position.z));
o.Albedo = IN.vertColor.rgb;
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Alpha = c.a;
}```
Is it possible in shader graph to wrap/repeat scale a texture without scaling UVs? Or will I have to manually loop the texture to a higher resolution in an image editor?
I have this spotlight aligned with the camera and it seems to draw a line based on the angle of the camera. If I look to the right it shows a full light spot, if I look to the left the light is obscured. Why is this happening?
Only 1 of you will have your questions answered. It's a game of elimination.
Pick me.
Hmm... I guess the spotlight could depend on the receiving mesh, and the render distance of the camera... I'm not sure.
It's strictly based on angle I can get really close and it still happens.
Now, answer the 20 questions I've asked that got buried and forgotten. lol
I'm guessing I didn't configure mesh nromals properly.
Mesh is procedurally generated.
That's likely the issue
Is there any automatic computation of normals?
Yes. There's a method for recalculating normals in the mesh API.
Not sure what you mean by "repeat scaling"π€
I think what you might be looking for is a triplanar shader.
$5 to whoever can solve my shader graph problem.
yo what is wrong with unity? Like I can't use the kayboard half the time. Focus on controls suddenly stops workin...lol how old is this engine?
I don't think I can instantiate a new mesh unless it's on the main thread. It's never getting past new Mesh
Yes it block my job. I need to figure out the actual math.
Does a normal have to actually be a unit vector?
You can't call most unity API from non main thread.
I've seen your problem but I don't entirely understand what's the issue.
What kind of math? Just recalculate the normals.
I don't want to calculate normals on main thread.
Why not?
squares are slow
Did you even try it?
yes
Well,then good luck figuring it out.π
Basically, my normals maps are showing up just fine, with the exception of the x-direction. I've used several different triplanar shaders in URP and none of them seem to work on this particular mesh for some reason. However, I used a triplanar shader in the Standard pipeline and the normals appeared, as normal.
It's easy when you know the math. I unfortunately have to figure it out the hard way.
The normals of the default cube appear just fine. But the normals in the x-direction of the custom mesh appear too glossy / gray
Which side exactly is the x- direction on this screenshot?
The side with the flat gray color
Are you using triplanar or uvs here?
It just looks super glossy.
triplanar mapping, but the mesh is UV mapped properly. the mesh actually looks fine without normal maps.
If you're using triplanar, the uvs are not used, so that doesn't matter.
Can you share the shader setup?
without normals, shader graph setup
i can share my github repo, if you'd be willing to take a look.
Doesn't look like it has any data.π€
Wdym?
it does, it's just super weak. i had to increase the normal strength in shader graph
Hmmm
Where did you get it?
freepbr
Doesn't look normal. Does it look the same way if you open the file with an image editor?
Vertex normal is actually an average of all the surfaces that use the vertex.
(β―Β°β‘Β°οΌβ―οΈ΅ β»ββ»
Depends. It doesn't have to be. But yeah, I think that's how it's calculated normally.
So it's like a huge pita to do so naturally there are no easy to find solutions.
Didn't you find the solution already? The average of surface normals.
It's a huge pita
This is the most promising thing I found and I just found it and I'm reading it.
Pita is middle eastern bread. What do you mean exactly?
On the basic level, you'd just get the directions of all connected vertices to the current vertex and average them.
That would be your normal
I think.
That would fail on a flat surface I imagine.
It would be 0 I guess. You can handle that case separately.
Yeah I could do it but it's on the todo list for now and I'll just use the builtin.
ok, i figured out the issue. i was using a custom unity asset that doesn't support shader graph. simple as that.
That or do it in 2 passes: calculate the normal per triangle, then calculate each vertex normals from the triangles
It still needs awareness of adjacent vertices or surfaces.
I would need to go over every triangle and for every corner I would need to add the surface normal to a list then after thats all done I would need average then normalize. At least I think that's right.
Okay actually it's easy.
I'll put code in #archived-code-general
Any idea how to force shader made with ShaderGraph NOT to be compliant with SRP batcher?
This is my use case, I have vegetation shader that will use instance instead of SRP.. but the thing is, SRP batcher keeps taking over
sorry for bad english
I found this to forcely remove the compatibility https://docs.unity3d.com/Manual/SRPBatcher.html#intentionally-removing-compatibility
But is there any way to do it directly in ShaderGraph?
Actually no this is a gist and it seems the normals do not need to be normalized? https://gist.github.com/d1ag0n/05416bea831e0e5a5e092bae7567287b @kind juniper
Assuming they're already normalized, averaging them out is gonna give a normalized vector as well.
(1+1+1)/3 == 1
They are not normalized.
Hey there, I've got a shader which has the following property, how would I go about accessing this property in code?
_Overlay ("Overlay", 2D) = "white" {}
My first thought was material.GetTexture("_Overlay"); - But that is returning a NPE so it isn't a texture, I have no clue how to get a property type of 2D
EDIT : In the inspector it's labeled as _Overlay Overlay (Texture)
GetTexture should work. What's NPE?
Null Pointer Exception
Running this on the material, I'm getting an output to say that _Overlay exists and is set, but when I try to actually get it, its null
I'm not sure if this is a shader/material problem or a C# problem
Nope- not a global property
Iβll ask the guy who set it up later when heβs awake. Maybe he can shed some light on what Iβm missing
I know using the Override Property Declaration in a property's settings can cause it to break SRP batching compatibility. Unless they've changed how that works.
Maybe set up a Float/Vector property, keep it Exposed but switch it to Global.
That way, I think it should keep it in the ShaderLab Properties section, but wont be defined in the PerMaterial cbuffer - which breaks compatibility.
Testing this now!
@regal stag I declare your from now on to be a shader GOD!..
It works!.. Thanks!
I literally wait for 2 hours just for this π .. thanks so muhc
Lets hope they would not change this in the future, or it will break my game hahaha π€£
what's funny tho, setting the MaterialPropertyBlock as suggested in the docs to break SRP compat didn't do anything...
I'm having a small problem with transparent shader. Basically, the transparent shader shows some of the inner face on areas supposed to have no transparency. Below is the difference of the same shader in opaque and transparent.
The shader is just this:
for context, I change to transparent when I change to a see through material (opaque + dithering doesn't give a very good effect)
Never mind, fixed with depth write forced enabled
any 1 got a basic light shader i can use?
that works with multiple light sources and spotlights
?
anything helps
what is that red thing?
I didn't think the actual lights were visible in the scene.
Unrelated, but may I ask where you get the stylized tree there?
Not even sure what I'm looking at. Maybe a video with moving around would be more helpful.
Is it same issue I just had last night? Does your mesh have correct normals?
it is custom made
ah I see... if you somehow upload it to Sketchfab, lemme know π ... I'll download it for sure π
Unfortunately, we will not upload it since we are trying to create a unique style that mixes 3d with pixel art, like in the picture below.
What shader are you using?
custom edit
Is it a graph or regular shader?
regular
vertex
o.vertexLighting = float3(0.0, 0.0, 0.0);
#ifdef FORWARD_BASE_PASS
#ifdef VERTEXLIGHT_ON
for (int index = 0; index < 4; index++)
{
float4 lightPosition = float4(unity_4LightPosX0[index], unity_4LightPosY0[index], unity_4LightPosZ0[index], 1.0);
float3 vertexToLightSource = lightPosition.xyz - o.worldPos.xyz;
float3 lightDirection = normalize(vertexToLightSource);
float squaredDistance = dot(vertexToLightSource, vertexToLightSource);
float attenuation = 1.0 / (1.0 + unity_4LightAtten0[index] * squaredDistance);
float3 diffuseReflection = attenuation * unity_LightColor[index].rgb * _Color2.rgb * max(0.0, dot(o.normalDirCalc, lightDirection));
o.vertexLighting = o.vertexLighting + diffuseReflection;
}
#endif
#endif
fragment:
float3 normalDirection = normalize(i.normalDirCalc);
float3 viewDirection = normalize(_WorldSpaceCameraPos - i.worldPos.xyz);
float3 lightDirection;
float attenuation;
if (0.0 == _WorldSpaceLightPos0.w) // directional light?
{
attenuation = 1.0; // no attenuation
lightDirection = normalize(_WorldSpaceLightPos0.xyz);
}
else // point or spot light
{
float3 vertexToLightSource = _WorldSpaceLightPos0.xyz - i.worldPos.xyz;
float distance = length(vertexToLightSource);
attenuation = 1.0 / distance; // linear attenuation
lightDirection = normalize(vertexToLightSource);
}
half3 ambientLighting = ShadeSH9(float4(normalize(i.normalDir.xyz), 1.0)) * _Color2.rgb;
float3 diffuseReflection = attenuation * _Color2.rgb * max(0.0, dot(normalDirection, lightDirection));
float3 specularReflection;
if (dot(normalDirection, lightDirection) < 0.0)
// light source on the wrong side?
{
specularReflection = float3(0.0, 0.0, 0.0);
// no specular reflection
}
else // light source on the right side
{
specularReflection = attenuation * _SpecColor2.rgb * pow(max(0.0, dot(reflect(-lightDirection, normalDirection), viewDirection)), _Shininess2);
}
float4 results = float4(i.vertexLighting + ambientLighting + diffuseReflection + specularReflection, 1.0);
may help
hey, i was wondering what is actually considered metallic? i thought it was gloss + some other stuff but i think thats probably wrong
metallic is related to how reflexive a material is, while glossiness is how smooth the surface is
a smooth material will be more shiny, but not necessarily reflect the environment around
obviously, a metal still needs to be smooth to reflect properly, but a non metallic smooth material won't reflect the environment
In other words, metallic tells how much the material reflects the environment, while smoothness says how much it reflects light. You need to reflect light to reflect the environment, obviously.
ok nice, i think i understand that
so to have more realistic metallics i want to maybe use something like image based lighting to get the reflections of the environment ?
and also change the reflection colors to the albedo colors?
Basically, yes. For example, the metal of a shiny car, or a mirror, would have something like 1 and 1 in both metallic and smoothness, while a wood with smooth paint would have 1 smoothness, but zero metallic
most objects have zero metallic, it's basically used when you want the environment (most of the times, the sky) to be reflected
however, lots of objects are smooth, like plastic, smooth paint and other surfaces
latex might have a bit of metallic to look cooler
coolcool, then i think i know what to look for to implement it 
I don't use it in my shaders since reflection clashes with the stylized style
it's useful for realistic style, among other mixes with cartoonish
yeah, im looking to just learn it for non stylized/more realistic look and then se if i can use it in anything else i do
hey trying to make a sprite shader but it looks weird after i add the material with this
Connect the A output to the Alpha port
Ooh.. makes sense thank you^^
Should be passed into unity_SpecCube0. Would be the skybox reflection, or a reflection probe, if renderer is inside the bounds of one of those.
There's also unity_SpecCube1 so you can interpolate between two reflections, which is useful for dynamic/moving objects.
Lots of related info here (for Built-in RP) : https://catlikecoding.com/unity/tutorials/rendering/part-8/
also, something that has been bugging me for months is: i have a water shader, i made it transparent but it stops receiving shadows, so is it possible to make transparent objects receive shadows? i'm using BiRP by the way
Afaik BiRP just doesn't support receiving shadows on transparent objects.
I think you can have an object in the opaque queue but still use blend modes to appear transparent, but then the skybox won't render through it. And other transparent objects are always on top.
well, pretty sad but okay
Im having some trouble fixing this bright burn out spot (the solid green)
It's happening because my values are exceeding 1 when it goes into the Arccosine
minmaxing it prevents it from breaking, but im losing the 'HDR' color potential that only shows above 1
How can I still use the arccosine but retain the high values after?
Arcsine needs the values to be between -1 and 1, but I need the values to go higher than that by the time it reaches the end π€ maybe I can try to move all my value adjustment to be beyond the arcsine
can you just multiply by something afterwards?
trying to bring it down before the arcsine and then back up again totally changes the appearance
Im very happy with how this looks, except all the bright green area is a value of 1
ideally it would be a value higher than 1
the arcosine is the bottleneck preventing this as far as I can tell
Maybe I need to not use Arcosine and instead impliment what it does but in respect to my use case?
I looked at the doccumentation and its just acos(#) so Ill have to google what the acos formula is
Is the Arccosine important? What happens if you just remap the dot product output a bit instead. Like from (-1, 1) to (3.14, 0)
I can try that, I tried removing it before but I lose the appearance in my earlier attempts
Hmm these values seem to allow me to replace the arcosine, it looks about 99% the same, at least in preview
there is a bit of difference but its not major
though the color burn out is still hapening so ill have to look further down the line
Maybe you have a saturate/clamp somewhere later?
yeah looking ahead there are saturates and min/maxes, ill work to remove them all now
I assume I put them all in in the past because the shader was breaking in other ways
ahh I found the problem I think
im adding a maximum here
because if I dont maximum it, the add totally blows out the entire appearance
actually the opposite, it looks way worse without the maximum
ill see if I can do some pow/mult here to fix it
working a lot better now π
the color green was also causing a lot of the burn out as well since you can barely see it turn into yellow at high values, but also it was clamped
Nice, looks great!
does anyone know how to get rid of these files in the final build? they're adding a huge amount of file size to my webgl build, despite the fact that we don't use filmgrain or any other post processing. I have the checkbox checked to remove unused post processing but its still being bundled
2021.3.6f1 version
In hlsl, if I wanted to use a function that returns a value (rather than outing a value) for utility purposes, could I set up some sort of (0f, 0f, 1f, 5f) for the return value, rather than making a new float4? Also, do utility functions that never get used in shadergraph need to have the _float suffix in their names? Thank you very much for your time.
you can do float4(0,0,1,5) (though that is just making a new float4); functions not used for shadergraph do not need to have _[type] in their names
Thank you very much for helping me out. By the way, by the mention of _[type], one would assume that many suffixes exist. In that case, why do some functions go by the suffix _float? Thank you very much for your help.
@zenith heronIDK what the last expression is, but if that's a float4 you need a constructor call as in:
return float4(0, 0, 2., 5.);
otherwise it is just a parenthetical expression that won't evaluate to a float4.
The suffix notation is a shader graph enforced standard for the return type
oh ok
You may also find it easier to use the .xyz or .rgb notation rather than the [0], [1], etc. for vector components. xyz is the same as rgb...you can use them interchangeably. By convention when dealing with colors you use .rgb.
ohh ok
makes more sense to use that
by the way, hlsl finds the fs in my numbers and sees them as errors. Is there no float suffix indicator such as float x = 5f or something? What about float x = 5F? Thank you very much for your time.
Hello, where can I report shadergraph errors? Unless these sorts of errors may be caused by the user and yet be seen as internal errors by Unity.
lol, I did that too without thinking about it....it's a C# convention. Use a decimal point instead in HLSL. I've edited the above.
Do you need it at all? I know GLSL whines if you don't put a point after ints when you want them to be floats, but HLSL seems perfectly happy with it.
For constants the compiler will usually substitute the proper value IIRC. I think it is smart enough to do that. But you can get burned in expressions that might assume ints. Maybe try something with an int like:
float myvalue = 1/three;```
and see if you get burned by int math.
just looked it up and hlsl does indeed do 1/3 = 0
Using Amplify shader
Can someone explain to me what Arc Cosine actually does
Like pretend I have to compute it by hand on paper.
Acos(#) is a black box, it means nothing to me, input goes in, result comes out
I tried to google it but I cant find an explination stupid enough for my dumb brain, and I asked in basic code because I forgot they're all elitists who only want to argue WHY you want to know something, and never actually explain anything
aparently the reason why you want to know an answer is more important than the answer itself, even after I gave them the #$%#$^ing reason repeatedly
It's because if you ever have to compute arccos by hand you're doing something wrong
and now im being followed by the person who is now harrassing me across channels great
blocked
Even before calculators people literally looked it up in a chart
i guess ill just go to an entirely different platform to get an answer
Asking about your attempted solution rather than your actual problem
Looked it up, someone on StackExchange said they use lookup tables and interpolate
Thats useful knowledge
I guess that explains why its so hard to find an answer or formula
when its not a formula, its a look up table of magic numbers
You also already got that answer
But I guess that's "elitist"
Even in the realm of maths it's pretty complicated and not very useful to understand how trigonometric functions work interally
What's important is to know all the ways they can be used
...Unless you're engineering calculators or CPUs from scratch
Careful. Insinuating they might not need to do this incredibly complicated math and that there's almost certainly an easier way to understand what a function is doing is "Elitist" and he'll block you
How would I create a reflection on the surface of a sphere?
There are countless different things a "reflection" could be
True, I guess before I worry about this question, I will need to have my custom SkyBox shader render into the reflection probe. Currently it shows as black.
I believe when lighting is generated from the lighting window Unity renders the sky into a cubemap texture (and an ambient light probe) which is then sampled for reflections by lit shaders
To make it work with custom skies or in realtime you may need to modify that process or replace it with your own
Cosine of an angle will give you a value between -1 and 1, ArcCosine will take a value between -1 and 1 and give you an angle. Hope that helps.
Cosine(1 radian) = .54... ArcCos(.54... ) = 1 radian
Do you know of any way to add tags to a shader created in the shader graph?
I am hoping I wont need to write my shader graph into a shader file.
I don't but maybe somebody else does
Sorry, I responded to the wrong post earlier. Cosine of an angle will give you a value between -1 and 1, ArcCosine will take a value between -1 and 1 and give you an angle. Hope that helps.
ArcSin and ArcCos will only give you a value over pi radians, or 180 degrees.
Is there a way to see a model's vertex colors in the editor?
create a shader that shows vertex colour
Ok thanks- was hoping there was something built in haha
Me too tbh
iirc Polybrush can paint vertex colors so it probably can display them as well
Yeah, but in the case of float4 foo = float4(1,1,1,1); the 1's would be auto-promoted to floats, I think. But in the case of float foo = 1/3 I think that ends up being evaluated as float foo = (cast to float) (int 1/ int 3 truncated via int division) so it's a bit different than your original question.
In a BiRP shader, you can sample the default cubemap for environmental reflections. Each draw call gets a default cube map that represents (I think) the closest reflection probe, or maybe a couple of probes are mapped in.
Anyway, I assume since you're dealing with SG you're NOT in BiRP (although it sort-of works for that too). But if you don't have a node for it already, you can write a custom function because IIUC URP will also "send" you a default probe.
In BiRP, the code to do that is:
v2f o;
o.pos = UnityObjectToClipPos(vertex);
// compute world space position of the vertex
float3 worldPos = mul(_Object2World, vertex).xyz;
// compute world space view direction
float3 worldViewDir = normalize(UnityWorldSpaceViewDir(worldPos));
// world space normal
float3 worldNormal = UnityObjectToWorldNormal(normal);
// world space reflection vector
o.worldRefl = reflect(-worldViewDir, worldNormal);
return o;
}
fixed4 frag (v2f i) : SV_Target {
// sample the default reflection cubemap, using the reflection vector
half4 skyData = UNITY_SAMPLE_TEXCUBE(unity_SpecCube0, i.worldRefl);
// decode cubemap data into actual color
half3 skyColor = DecodeHDR (skyData, unity_SpecCube0_HDR);
// output it!
fixed4 c = 0;
c.rgb = skyColor;
return c;
}```
This is from here: https://docs.unity3d.com/Manual/SL-VertexFragmentShaderExamples.html
Note how they compute the necessary reflection vector in the vert() stage...so as to only do it 3 times per polygon, and then in the frag() stage they decode the results after sampling the reflection probe. In SG, the reflection vector would be a custom interpolater if it isn't natively available otherwise.
Is this description an explanation of making a custom reflection shader?
Hey, how can I change the shader when it's greyed out?
I want to change the shader to something so the tea pot is rendered through the box
You can't modify an imported model asset directly. Need to either create a prefab from it or modify it in the scene. Also the way you (did not) imported the material probably prevents it as well.
Thanks. I've got a fbx file for that tea pot, how would I import it correctly?
Because all guides I've previously seen always said to just drop it into the assets
Select the fbx asset, go to the material tab and take a screenshot.
Just reimported in case it matters that it's still a packed prefab
You meant the material in the inspector, right? Or is there a separate tab for the material?
Select the teapot root asset. It should bring the fbx import settings, which have the material tab.
This one? Do I click the 'extract materials' here?
Yes, click it
Just for your info, all this does is just create a new material, assign it to the renderer and set whatever properties it can understand from the fbx file(like the textures). You can totally do it manually.
Okay, thanks. Now it lets me change it
Could it be pink here because I made a mistake in the shader code?
Yes. Pink means a broken/incompatible shader.@azure lichen
If you don't mind me asking you more;
How can I upgrade my shader to be compatible with URP?
If it's a custom shader, then you'll have to rewrite it in hlsl(really just some minor changes)
Yea, it's a custom shader, not too complex either
Shader "Custom/AlwaysOnTop"
{
Properties
{
_Color("Color", Color) = (1,1,1,1)
_MainTex("Albedo (RGB)", 2D) = "white" {}
_Glossiness("Smoothness", Range(0,1)) = 0.5
_Metallic("Metallic", Range(0,1)) = 0.0
}
SubShader
{
ZTest Always
Tags { "RenderType" = "Opaque" }
LOD 200
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
half _Glossiness;
half _Metallic;
fixed4 _Color;
// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.
// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.
// #pragma instancing_options assumeuniformscaling
UNITY_INSTANCING_BUFFER_START(Props)
// put more per-instance properties here
UNITY_INSTANCING_BUFFER_END(Props)
void surf(Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
// Metallic and smoothness come from slider variables
o.Metallic = _Metallic;
o.Smoothness = _Glossiness;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}
Its purpose is just to layer the object with that shader on top of everything
Hmmm... I don't see how exactly is it different from the standard shader
What's the part that makes it render on top?
I see. In this case, you might as well take the URP lit shader template and add that line to it. Might be simpler.
Otherwise check Cyan's article on changes between birp and urp shaders:
https://www.cyanilux.com/tutorials/urp-shader-code/
Explains how shader code (ShaderLab & HLSL) is written to support the Universal RP
Oh, btw it seems like the ztest is exposed as the shader graph property in the shader graph now. So you could create a shader graph and adjust that property in it.
In 2021 though.
I've just inserted the ZTest into the URP lit shader as you said before and it works. Now also my AR apk works as intended as well. I've got stuck on that single issue for way too many days now. Thank you alot. You have no idea how happy I am that this runs now π
Yea, Apparently there were a lot of solutions to my issue by using the 2020 or 2021 version of Unity, but then I'd have other compatibility issues on other ends which I wouldn't be able to fix
Donno. There aren't many breaking changes between 2019 and 2021 lts.
It's mostly related to Vuforia at that point. I've been trying some of the 2020/2021 solutions that I found, but I'd usually run into compatibility issues, even after building up everything from nothing again. First starts with things like ARCore bugging, then Gradle, then Vuforia because of ARCore, etc.
Well, at least it's working now.
Hello, where can I report shadergraph errors? Unless these sorts of errors may be caused by the user and yet be seen as internal errors by Unity.
I create a surface shader and a material.It displays purple.I tried do upgrade to URP.But it doesnt work. says"Custom_NewSurfaceShader material was not upgraded. There's no upgrader to convert Custom/NewSurfaceShader shader to selected pipeline"
How to write a transparent surface shader in Unity?What kind of shader ppl usually use for transparent shader?Unlit?Or standard?I know how to write transparent in unilit.But could anyone show me an example of transparent surface shader?
Sorry for not responding to this for a while, but would this be in a Compute Shader or shader graph?
Went not use the shader graph?
Neither. Sounds like a regular shader. There might be a way to do it with a graph though, but I don't know the context and too lazy go back and read it all.π
Anyways, it's definitely not a compute shader, as you don't use it to render stuff.
Like a custom shader or one of Unity's default?
Custom shader.
Oh ok, i have no idea how to write a custom shader, and im barely understanding compute shaders.
Im trying to setup unity chan toon shader and according documentation i should use "rendering path -> forward", but i am not able to find this option.
Some tutorials also advice to use UTS2 Pipeline asset, but i cant choose it under graphics.
How can i setup this option ?
(i am on android platform)
Hi there, not sure if this is the correct channel, but I'm trying to apply some shader magic on the camera of a device, and then export said image to a PNG. Is this something that can be done with shaders? I was looking into Custom Render Textures, but I'm not sure if this is the way forward. Does anyone have any suggestions on how to proceed?
ive gotten reflections of the skybox working, but it seems like im not adding it to the rest of the shader correctly. it might be that i have the metallic variable correct.
it doesnt get to that mirror like reflection this way
float3 reflectionDir = reflect(-V, i.worldNormal);
float4 envSample = UNITY_SAMPLE_TEXCUBE_LOD(unity_SpecCube0, reflectionDir, _MetallicRoughness * metallicMap * UNITY_SPECCUBE_LOD_STEPS);
float3 diffuseIBL = DecodeHDR(envSample, unity_SpecCube0_HDR);
light += diffuseIBL * _MetallicIntensity; // light is diffuse + specular + fresnel
Its in your urp renderer asset, and it should be set as forward by default already, unless you changed that ofcourse
i think i got it working, this looks a little better
you are missing ztest and zwrite
No,It has nothing to do with the cube.I want the black part be transparent
you still need to write to the depth buffer if you want it to be transparent
or not to write to it i guess
I added "Zwrite On" or "Zwrite Off",Still doesnt work.Nothing happened.Im new to coding shader.
you need all the keywords to be set for a transparent shader, and then you need to set the alpha to be <1 (and >0)
Is there any way to scale the displacement of a graph in a similar way to a triplanar node on a texture?
I mean, when you scale the object, it just repeat the displacement instead of enlarging it (Update: FIXED)
..triplanar node on a texture you mean the offset uv for the texture tilling?
this is my shader code https://gdl.space/yupatixare.cs, why does it have blacklines like this?
you're not using some sort of fullscreen effect? like PP for outline effects for example
I am following a tutorial
this one
yeah. But I want to offset the vertex part instead of fragment
vertex position
btw you can check the code
that I linked
ive noticed that my shaders isnt effected by this value. how do i access it?
you have to either create a custom node, or modify lighting.hlsl
You're looking for the wrong person here... I'm just an NPC in this channel π just wait
lol
ok
It's strange.Wanna make a portal.Why it only works in solid color?
#pragma surface surf Standard fullforwardshadows alpha:fade
I used alpha fade
oh you are using surface shader lol, i didnt check that when i first looked at it. that would make sense
Kinda difficult question but I'm running a compute shader that updates a large image, and the more times it runs the longer each iteration takes, when in theory it should be running on fresh data each time, is there a step I could be missing, like releasing a buffer or something? It gets the the point where I have to force shutdown my computer if I don't stop it in time
this is my shader code https://gdl.space/yupatixare.cs, why does it have blacklines like this?
That looks like AO to me. If you're using URP for example, you might have SSAO turned on, or you may be doing it in some other post processing.
I am not using post processing, or urp, only a basic 3d project
Did you bake your scene?
Have you tried the memory profiler to see if there are some memory leaks happening somewhere?
how can i turn passes like these into a for each loop to reducee repetition?
Pass
{
Name "Forward_Fur"
Tags {"LightMode" = "ForwardBase"}
CGPROGRAM
#pragma multi_compile_fwdbase
#pragma vertex vert
#pragma fragment frag
#define FORWARD_BASE_PASS
#define _FURLAYER 0.0
#include "FurHelper.cginc"
ENDCG
}
Pass
{
Name "Forward_Fur"
Tags {"LightMode" = "ForwardBase"}
CGPROGRAM
#pragma multi_compile_fwdbase
#pragma vertex vert
#pragma fragment frag
#define FORWARD_BASE_PASS
#define _FURLAYER 0.0526315789473684
#include "FurHelper.cginc"
ENDCG
}
pass
{
etc...
The memory section on the normal profiler gives this, but I'm not too sure what to make of it:
Reserved Total: 0.64 GB Unity: 299.3 MB Mono: 21.3 MB GfxDriver: 64.8 MB Audio: 1.2 MB Video: 0 B Profiler: 273.0 MB
Total System Memory Usage: 20.39 GB
Textures: 1559 / 19.23 GB
Meshes: 276 / 1.6 MB
Materials: 46 / 89.0 KB
AnimationClips: 0 / 0 B
AudioClips: 0 / 0 B
Assets: 2293
GameObjects in Scene: 8
Total Objects in Scene: 1354
Total Object Count: 3647
GC Allocations per Frame: 0 / 0 B```
The 19.23 GB looks kinda alarming but I'm not sure if that's normal
You better use the Memory Profiler to get better idea what is consuming the memory
Hello!
So recently this asset https://assetstore.unity.com/packages/tools/particles-effects/true-clouds-fog-mobile-pc-107379?aid=1011l37no&pubref=indie&utm_campaign=unity_affiliate&utm_medium=affiliate&utm_source=partnerize-linkmaker was made free on the Unity Asset Store. But it is not compatible with URP or HDRP, runs only in the Standard Pipeline. I wanted to port this to a URP project but I only know beginner-level HLSL. Can someone point me in the right direction as to how to make this asset compatible with URP? As these shaders were written before it URP was released.
Apologies, where can I find that? I wasn't aware there was a separate memory profiler
You can google how to do that. I think you have to download a package for that to work
Thank you! I think I found the cause, running Release() on the RenderTextures I created each iteration wasn't enough, it looks like by running Destroy() afterwards on them that I've resolved the issue, as this marks them for the GC
Great
is there a way to detect, within a shader, if an asset is being rendered as a preview?
Like in shader graph?
IIRC, in a custom node, you can do it with compiler conditionals.
#ifdef SHADERGRAPH_PREVIEW
I think that works for the shader graph preview window, but not for the asset preview window
(the one that comes up when using the inspector to look at materials/objects, for example)
it's this issue specifically I'm trying to work around - I have an effect which needs to know the exact viewport size, the only way I can think of is to store that in a global variable, but then there is a race condition when rendering the preview window https://forum.unity.com/threads/race-condition-when-rendering-preview-window.1336478/
If I could switch the logic in the shader I might be able to work around it
btw for URP > 10 I think you have to use defined(SHADERGRAPH_PREVIEW)
a rather frustrating api change
@teal breachHow are you setting that "global"? With Shader.SetGlobalColor?
In a custom render pass I do buffer.SetGlobalVector("_RenderTargetInfo", new Vector4(renderingData.cameraData.cameraTargetDescriptor.width, renderingData.cameraData.cameraTargetDescriptor.height, 1.0f, 1.0f));
(incase anyone is wondering 'why not use _ScaledScreenParams' - it doesn't work reliably unfortunately https://forum.unity.com/threads/_scaledscreenparameters-and-render-target-subregion.1336277/)
nope
Is it able to wirte a transparent surface shader?
Is there any ez example code of tranparent surface shader?
so ive been trying to properly apply my metallic reflection. i have the reflection working how i want with roughness and metallic map and whatever, but i cant figure out how to properly apply it.
if i multiply the reflection straight into the albedo like this
float3 output = albedo.xyz * reflection * (light * _MainColor + specularLight + saturate(fresnel) * _ColorRimLight * _ColorRimLight.a * light);
it looks correct if the metallic is equal to 1. but this way it also makes it go black if its 0. but if i try anything else it doesnt get the correct color. ive tried a lot of different things like
float3 output = albedo.xyz * (light * _MainColor + specularLight + saturate(fresnel) * _ColorRimLight * _ColorRimLight.a * light) + reflection * albedo.xyz ;
and
float3 output = albedo.xyz * (light * _MainColor + specularLight + saturate(fresnel) * _ColorRimLight * _ColorRimLight.a * light + reflection * albedo.xyz);
someone said that the reflection should be multiplied with the black albedo but it doesnt seem to look right if i just add it on top
what am i doing wrong?
from digging around, I've also found that this define only works for the thumbnails in the individual shadergraph nodes. It doesn't work for the 'preview' window in shadergraph, which it seems you have to test for using SHADERPASS == SHADERPASS_FORWARD_PREVIEW after making an #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl". I hadn't noticed that before!
I just needed it for something else, thought it good to share π
I am having some difficulty getting a desired look out of this shader im working on.
Pictured first is what I want to see, the interior backface refracted. I have it working but only from certain camera angles.
Pictured second is what happens if you look at it from a certain angle, the "interior" gets completely lost
I can't seem to figure out how to adjust the shader so that the interior doesn't get lost at certain angles
the coordinates arent the problem as far as I can tell, they never get lost no matter the viewing angle (sorry broken gif)
which leads me to believe its getting lost somewhere in here
plugging it in to the output one node at a time, it seems to vanish at the dot product
my end goal is to accentuate the faces so they are clearly present from all angles
I have this that draws a box that I could use to make the faces more pronounced, but I cant figure out how to modify it so that it uses the refracted faces
(HDRP) This gets me a nice circular shape... what would I do to achieve a more diamond-shaped version of this?
racking my brain thinking about it
will this suffice?
you can change its shape by adjusting the tiling in the tiling+offset but till need to be recentered
Yeah thats about the same thing
not sure which is more performant or better fit for purpose, but it's a start
you can go more general than that too; do (r^p + g^p)^(1/p) and then by changing p, you can get from diamond at p=1 to circle at p=2 to square at p=inf @timid minnow
I figured there'd be a smarter answer, that is the limit of my ability
(btw this is called the p-norm of the vector)
struggling to get the white appearance but on the coordinates of this other texture π€
distance and length don't form the cube
hmm maybe I should do what I just showed that person, the absolute maximum?
wdym by "on the coordinates of this other texture"
I want the white appearnce, but with refraction making the surfaces not cubic
ah this doesnt work at diagonals
all of this is XY
what I really want is to make the interior faces at certain angles not vanish as seen above
How do you blend between them?
I don't
the white one is not used at all in the method
the only reason its there is because I was trying to get it to work like the other one so that I could blend them
I guess the problem is that i want to blend them but I dont know how to make the white one respect the refracted ones surfaces
this almost works but its got a dumbass cross in the middle of it
minimums, adds, maximums none provide the desired appearance
maybe subtraction?
nope even worse
I want this white like this
again this is all xy
I just want the interior faces to stop vanishing
and every attemp of the dozesn ive tried have failed
I cant boost the values, I cant negate the washout, I cant do a single #$%#&^ing thing I want do with it
and now im starting to go into crsisi because im a stupid fucking failure
time to take a break
Where have I gone wrong, sensei?
that looks right but your origin point is at the bottom left
if it was centered you'd have the same diamond as before
just discovered a tiny bit of black broken texture in the corner of my mesh
maybe do 1+dot(face normal, interior position)
i have implemented normal map into my shader and now if it doesnt have a map on it kind of loses its smooth shading, to get rid of that i want to use the regular normals instead of from the map. but i dont know how i can switch between those when it has a map and not a map since it would be done differently
float3 N = normalize(i.normal); for without a map and
float3 N = mul( mtxTangToWorld, tangentSpaceNormal); for when i have a map
how can i change this?
how to make the black area of texture be transparent like in shader graph when writing a custom shader
https://assetstore.unity.com/packages/vfx/shaders/lava-flowing-shader-33635#reviews real quick, does anyone know why the lava doesn't scroll? i followed their doc
if (length(color.rgb) == 0)
{
color.a = 0;
}
Any obvious reason in Scene view, this tiles correctly based on Object scale... but in play mode it does not?
Do you want the top one?
How come I cant connect the Multiply output to the Vertex Normal?
if so, I don't thin you need to do the tiling and offset bit, just use the UVs directly (they scale with the object)
I think you can only use Normal Vector in the fragment stage perhaps?
bottom, tiled proportionally with the object scale
that's what scene view produces
Well, I got the Split and Combine nodes to work, but it seems to be picky about what I feed back into the Combine node:
Is Front Face node can only be used in the fragment stage
Oh, I guess that makes sense
Perhaps the objects are marked as static? So would be using static batching, which combines meshes and overrides the model matrix (which the Object node uses for calculations)
Usually the normal map texture property is set to "bump", which uses (0.5,0.5,1,0.5) if no texture is assigned.
_BumpMap("Normal Map", 2D) = "bump" {}
That should fix this, since after sampling & unpacking, that results in a tangentSpaceNormal of (0,0,1) - which is equal to the world space mesh normal.
Alternatively, you could also use a mutli_compile or shader_feature in the HLSL code to make the shader generate multiple variants.
#pragma shader_feature_local _NORMALMAP
Could then do
#ifdef _NORMALMAP
float3 N = mul( mtxTangToWorld, tangentSpaceNormal);
#else
float3 N = normalize(i.normal);
#end
But to actually enable the keyword when a texture is assigned you'd need to write a custom ShaderGUI, or could just use an additional property to add a toggle. e.g.
[Toggle(_NORMALMAP)] _NormalMapToggle ("Normal Mapping", Float) = 0
Well, I got this far with my cross section shader, my problem now is that it shows things that are further back than Z0, and culling the back of the camera view will just mess up the effect. Is this the wrong approach to this effect or is there a way I can fix this?
That was it, thank you! Never would have thought of that... but now, I will never forget!
Thankyou that works
When GPU-instancing, I'm guessing all the properties have to match to batch properly, but does that extend to textures that have been assigned?
For example, if I have a material for bricks, and one for wood. Both share identical properties except the textures assigned, would they batch together? or is it effectively 1 per material?
How do I use compute shaders? I wanted to reference this white noise generator compute shader.
Not even all matching properties is enough, it needs to be the exactly same mesh and same material
does it take into account the textures assigned though?
It needs to be the same material reference, not same shader
ok, that makes sense
If you make exact copy of one material and assign them to two identical meshes, gpu instancing will not realize they are the same material even tho the properties are the same
Is it possible to utilize the same material more than once, but modify some property? e.g. color/hue/saturation?
I used MaterialPropertyBlocks to achieve that, if your referring to runtime changes @marble thunder
Srp batcher on the other hand requires only same shader (so can be any material with any properties if the shader is same)
Yep, completely forgot that, nice catch
my obsession with optimization sometimes yields results XD
If you want only best results, you should only use RenderMeshIndirect and pass all the arguments to the shader as buffers π (only useful for huge amount of same objects, dont actually do that in every situation, could be useful to something like custom particle effects)
im dipping my toes into ECS so gonna try sub-scene everything, also just finished setting up Virtual Texturing, so hopefully that will give me plenty of FPS to play with
I'm curious about writing shader code here, which one would be more practical to read? The single line or blocks of code step by step in comment:
I like the single block of code more. As I feel it is more mainstream way to write shader code, its clear enough. If you do the latter option, your shader code may become way too long to remain readable
?
The order of operations isnt really that important as everyone can pretty quicly figure it out using the basic math rules
Is it possible to write a custom shader for portal effect?
Sure? You'd probably use RenderTexture better?
(The shader could be used to draw the portal rings)
How to turn the black area of texture into transparent?
Id still prefer the first option but this isnt bad either
I dont know much about Rendertexture...
Compare the color value to match below 0.01, 0.01,0.01 -> 1-x -> clamp, then assign it to the opacity channel.
I'm writting this portal effect in unlit shader.How to make the black side transparent?
Are we talking about effect like this: https://youtu.be/w0znZIuvQ2I or teleporting/portal system like this: https://youtu.be/cWpFZbjtSQg?
First one
Got it
you are on the right path.
You can make it a png
or just get the value of the red channel and assign to your opacity channel
Do you have these lines on the shader code?
Tags {"Queue"="Transparent" "RenderType"="Transparent"}
ZWrite Off
Blend SrcAlpha OneMinusSrcAlpha
I actually want the shader can do the same as the shader graph that get value btween 0 and 1(0 is black, 1 is white)
YUp,I have
Then you should be able to just set the fourth component of the float4/fixed4 you are returning at the end of the fragment function
Ah its surface shader
sampler2D _main_texture;
...
const float4 text = tex2D( _main_texture, i.uv );
text.a = text.r;
return text;
The last one is surface shader.I dont know how to set it.Cz it display on the scene but not in game view
The sec one is unlit shader.Which works well.But Idk how to set it black part transparent
@clever saddle for me it seems your code is having something very different than what I showed
And the unlit shader doesnt even have the Blend command
Nor does it have ZWrite off
I tried your code line.It's effect like this
There's a slightly background glitch
Thx,It works!!!So miracle
Nice!
Thx.That's a solution 2.It works
I got another problem.I'm trying it(red one) in unlit shader.But it didnt visible itself,it just blend with other object
It varies by pipeline.
That's what material-property-blocks are all about. But the SRP batcher deals with things differently than does BiRP. IDK about HDRP, but it's likely different than BiRP too.
So IDK what pipeline you're in, but a texture reference CAN be in a Material Property Block.
https://docs.unity3d.com/ScriptReference/MaterialPropertyBlock.SetTexture.html
BiRP instances by material...they all have to be the same material but the actual data can vary by the contents of the MPB. In SRP it instances by shader, and God help me I can't figure out why it doesn't use MBPs the same way, but it doesn't (mostly because you could have several materials for one shader, I guess). And there may be differences between hand-written SRP shaders, and SG versions.
Yeah thanks, I already use MaterialPropertyBlocks so that ties in nicely
Might be depth clipping. Setting 0 alpha can be a problem. You have to make sure you're not writing to the depth buffer. (ZWrite Off) like @dim yoke said.
The other way to do it (and some worry about low-end mobile device capability/speed) is to use alpha clipping and discard pixels that don't pass some test. That way you don't update the depth buffer if you want to write to it.
Hi guys I wanted to know how to make Single pass Instance work on shaders that I have made using the Shader graph.
Currently what happens is i can only see it from one eye and not the other. I have checked the gpu instancing on the material that uses these shader.
is it possible to get a gameobject by tag and gets itsposition in shadergraph??
You can't get a gameobject in shaders. You can't pass strings into a shader either. You have access to the rendered object position though. I think it's the position node..?π€
Ah, it's the "Object" node
If you need access to a position of a different object, you'll need to pass it in as a property from c#
k
Hello, I am having an issue involving Custom Functions. My Custom Function is called SetPenColor, where I set a pen's color based on the 0-1 hsv value I give it. It involves converting the circle data from the Ellipse node to an hsv, altering the hue, and converting that back into an rgb for usage. However, whenever I drag the circle data onto the Custom Function, a strange error occurs where the Shader Compiler crashes. I was thinking it may have to do with my code, but I can't seem to find any more errors. I wanted to come here to ask for any advice on the matter. Thank you very much for your time.
Where is the custom function code file in your project?
Also, where do you define cMax3 function?
And cMin3
is there a global paramter that i can pass that will effect all materials using same shader??
I think so. Check Shader api docs.
wait should I perhaps delete that shader file on the very right?
I was just playing around with it another time
why not just use HLSL max/min?
it..exists??
abs exists too
O:
Probably not
But you can nest them: max(max(a, c), max(b, c)) or something
yeah!
Ah, your custom function definition is not correct.
You must not have a return type.
wait really
Yeah you can do it, but I think it's not a great practice.
That's just for including other files. If you want to use functions defined in different files.
Ah maybe not
Basically it's a preprocessor definition. I'm not sure what purpose it serves in this specific case. Might be just something they left there.
Maybe they toggle it off somewhere so that the function does not compile.π€·ββοΈ
Or so that it doesn't compile twice.π€
It's so if you use the include file in multiple Custom Function nodes it only compiles it once. Would cause redefitions otherwise
Ah, that makes sense.
While learning how to use Custom Functions is useful, if you are trying to convert between RGB and HSV there is also a Colorspace Conversion node
The error is probably due to wrong custom function syntax
I also can't remember if you're allowed to use the [index] syntax on float4 to set values. I think it might only be read. May need to use .r or .x, .g or .y etc
oh! seriously?
rxgy?
yeah xyzw! i remember that
i remember thinking w came first too
and finding out
so
I'm setting the values of an argument apparently
that's bad right
Yeah, it's not allowed sometimes, but you get explicit error about that.
The last one is still using indexing. But I'd worry about only when you get the actual error.
alpha ranges from 0-1 right not 0-255 unless I'm wrong
All components are 0-1 in the shader
.
so dividing by 255 was actually just a really bad idea