#archived-shaders
1 messages · Page 241 of 1
Um they take vertices count + positions, make a shape out of it and then apply a texture to it. Shaders can do anything with the input data tho
Also there is some work with light, but I don't know how it works
yeah. so in forward rendering path all the lights are rendered in the shader itself. the shader takes in list of lights as input and using that calculates how to color pixels so they have lighting on them. Per pixel lights are calculated this way. Per vertex lights on the other hand are calculated on the vertex shader (which is used to place the vertices and transform mesh data (position, normal, uvs, etc.) and if you wish some additional data to fragment shader where the data is interpolated per every fragment (pixel)) so the vertex shader uses the light list to calculate how the lights affects the vertex. the lighting data calculated on vertex shader can then be interpolated to light the pixels on the fragment shader. per vertex lights tend to give quite blurry and bad quality lighting 🔽 compared to per pixel lighting ⏬ but can be a lot faster because usually there's fewer vertices than pixels to render
This did work for the mask but not for the noise ^^' but this is already of great help, thanks!
Well it does "work" but because the noise function you're flipping is virtually infinite you don't really see it
You could use a noise texture instead of a noise function to get a traditionally flippable sort
Cheaper too
This could actually be a better solution indeed, thanks for the suggestion! Will try it out
But I see such events in Forward Renderpath. Nothing about lighting
Besides, I see such events in deferred renderpath
both per vertex and per pixel lighting are done in Render Opaque Geometry state on the same shader that calculates the textures etc.
on deferred rendering shaders only calculate the base color, normal etc. and stores them in so called G-buffer which is then used to calculate the lights after every opaque mesh is rendered to the buffer
So can you tell me what exactly is stored in G-Buffer? It would answer at least one of my questions
It seems it contains atleast albedo (base color), specular, occlusion, normal, smoothness, emissive and depth
I removed that. I saw that on somebody else's code and decided to try it. I kinda hated the way it worked. Anyways, even with it removed the artifacts are still there. When you refer to the sampler state settings, what exactly are you talking about? The _MainTex is just the main render texture of the camera, as it is a post processing effect.
Can you please elaborate how all shaders and a renderpath related to each other? Also please tell me whether a vertex shader is always followed by a pixel shader and whether a pixel shader requires a vertex shader before it to work
that's true. vertex shader is always run first which iterates over list of vertices and pixel shader then renders the pixels of the mesh constructed on the vetex shader
So both answers are "yes"?
yup. I don't know how to explain the first part (render path and shader stuff)
Do you think I first should learn a bit about how to write shaders?
Asking just to be sure: so there are always at least two shaders on an object, vertex and pixel. Is that so?
yes. on all render paths everything is rendered using shaders that are made of those two stages (vertex and fragment stage). basically on forward path everything (lighting, textures, shadows etc.) is calculated on the shader itself and on deferred path lighting calculations are done after every shader have ran as a sort of "post processing" effect. forward rendering is pretty straight forward and that's the default rendering path in unity. I'd recommend learning about writing shader (with forward rendering path) as it makes it much easier to understand how shaders works internally (vertex stage, fragment stage, interpolators, passes etc.). Imo this was really good tutorial/introduction to start with https://www.youtube.com/watch?v=3penhrrKCYg&t=2982s (I watched that about 1-2 years ago so i'm not very "pro" with shaders yet).
learning to handwrite shader makes it also much easier to use shader graph because most shader graph tutorials just teaches you to make cool effects and not how shaders really work
yo guys can i ask here about how to properly apply textures to scene . im noob and need help
Okay, so I checked out sampler state settings and those don't work in my case because it is a post processing effect that takes the texture from the main camera. Really the thing that I'm confused about is the pixel artifacts. It all seems to be working except for those odd pixels.
Oh hey, I just figured it out.
It wasn't on the GPU side, it was on the CPU side.
Hi, what is the easiest way to get the angle between two 3d vectors in HLSL?
Okay thank you, but would it be easier to learn with the unity shader graph or just by code.
shader graph is generally thought of as easier to learn, but i personally am a programmer and i want to understand the math and reasoning behind things. and i learn those things way better with code than a graph
If you learn handwritten shaders, you don’t need to learn shader graph separately, it’s like 10 mins and you’re pro with shader grpah (assuming you know handwritten shaders already)
Okay thank you for your time responding me
Awesome, thanks. But uh, how do I normalize the vectors?
normalize(vector)
The problem is that there’s not many tutorials that really teaches shader fundamentals with shader graph. Most of them just show cool effects which doesn’t help much when you want to do something yourself
Yeah, and I can't find any useful documentation either
i personally find there to not be many tutorials for shaders overall. its either super simple things or fairly complicated stuff
i sometimes look at other shader tutorials for other languages and programs, like blender for example. since the theory is pretty much the same. and once you know what you need to do its easier to google things
Documentation tends to be very poor what comes to shaders
Thanks for the help
actually this is exactly the reason i have started to document all the stuff i make relating to shaders and graphics
yeah, that's probably smart
Also, is there a convenient way using a surface or frag shader to just have a visible pixel of a mesh just not render and have it render whatever is behind it instead?
You can use discard or clip function (which is just discard under the hood)
Okay thanks, I'll try that. But how does it work?
discard just ”ignores” the pixel and clip discards if the value you give it (or any component of it) is negative. Clip can be useful when you want to ignore pixels with alpha value less than 0 (usually something like clip(alpha - 0.001) so alpha of 0 gets ignored too)
That makes sense, but how do I use the function? Like what do I type and where?
(I'm sorry I'm completely helpless Lol)
For example ```cs
if (col.a < 0.01)
{
discard;
}
or
```cs
clip(col.a - 0.01);
You can do that anywhere on the fragment function (it’s recommended to do that as early as possible because afaik the shader stops executing for that pixel so you can save some performance (well, dynamic branching is bit weird because of wavefronts and stuff)).
Np, clip/discard is great way to make some pixels fully transparent because it works on opaque shaders too and allows to do cool effects (like dithering transparency) with minimal overhead
Can someone help with setting up GPU Instancing? I have a world made up mostly of these brown cubes, there are around 500 of them.
they're literally all cubes, with gpu instancing set up
Does it just not work for Orthographic forward rendering?
There is literally nothing operating on these cubes right now, they are all the same prefab
(Using the standard unity shaders)
Can someone help me with shaders because I don't get them I'm making a 3d game third person and i just can't do the water shader
So what have you tried so far?
I can show you @dim yoke in a call if you want to
Why not just show here so everyone can help?
@eager egret Don't crosspost.
Ight, so I'm back with another question 🎉 .
What would be the best way to get something like the camera position or the position of a specific object (like the player) or some other universal but changing value in HLSL?
Whats the alternative to byte data type in a compute shader?
Also for this, a struct on the C# side of things doesnt allow constant buffer sizes? So then how do I send it in without having to copy all the data to an intermediate buffer? its a bunch of arrays of type int with length 8
as in, this is the structure of the array
struct BVHNode8Data {
float3 p;
uint[3] e;
uint imask;
uint base_index_child;
uint base_index_triangle;
uint[8] meta;
uint[8] quantized_min_x;
uint[8] quantized_max_x;
uint[8] quantized_min_y;
uint[8] quantized_max_y;
uint[8] quantized_min_z;
uint[8] quantized_max_z;
}
Is it possible for me to have this same structure on the CPU and send it nicely? Because I just cant copy all the data to an intermediate structure with them all layed out cuz thatll take too much performance(talking about doing this 30k times at least per frame)
also on the C# side those uint arrays are actually byte arrays but HLSL doesnt have the byte data type
Anyone have any idea what's causing this error?
Steps needed to recreate (Unity version 2021.3.1f1 Personal)
- Create brand new 3D project
- Create Unlit Shader Graph
- Right-click newly created Shader Graph and create a Material from it
- Material turns pink and gives the error shown in the screen shot.
When I last did a BVH acceleration struct it was a b-tree, not an oct-tree. So I only had 1 min and 1 max in the struct, basically.
But there is a way to set/access fixed length data in a struct from C#, it allows interaction with other languages/systems, I just don't have the time to answer now as I have to run off to work. Google is your friend. Maybe see "MarshalAs".
Table of Contents1 C# Fixed Array1.1 Fixed Size Buffer In C#1.2 C# Fixed Size Buffer Sample1.3 Benefits Of Fixed Size Buffer In C#2 FAQ on C# Fixed Arrays2.1 How to Declare Fixed-size array of struct type in C#?3 Summary C# Fixed Array This article covers declaring a C++ style fixed-size structure was difficult in earlier […]
That last one looks cool.
wut the many problem. why i set red base col but the preview is purple WHY?
purple means compilation error on the shader. most likely your scriptable render pipeline isn't set up correctly or you're using old enough built-in render pipeline which doesn't support shader graph at all
Is it possible to make an unlit shader that renders itself or other objects shadows?
(In shader graph)
Do a mesh's vertices also store colors inside them? Or the colors are stored in the mesh?
Also please give me a good info resource about this if you know one
is there a way to change the dither matrix size in shader graph?
as I'm trying to make the dither dots be similar-ish in size to the pixel size of the character
oh ok
Random find in Unity 2022.1 release notes:
Editor: Now shaders will have SHADER_API_(DESKTOP|MOBILE) define set according to the target build platform.
Override the screen position input of the node, to match you pixel size.
Should be as simple as taking the screen position node, and dividing by a constant.
ooh sweet, gonna try that
it works great, thank you!
Hey, what would be the best way to pass a Vector from a script (like the player position) to all materials of the same type?
You could use a global shader property, e.g. via Shader.SetGlobalVector("_PlayerPos", playerPos) https://docs.unity3d.com/ScriptReference/Shader.SetGlobalVector.html
Use the same property name in the hlsl portion of the shader, but unlike regular properties, don't include it in the Shaderlab Properties section at the top.
For shadergraph, untick the "Exposed" tickbox under the property settings.
You can use Custom Functions and some specific boolean keywords to make shadows work in an Unlit Graph.
I've got a "Main Light Shadows" SubGraph included in this repo, which handles both for you. https://github.com/Cyanilux/URP_ShaderGraphCustomLighting
If you need additional shadows too, you'll need to write a function similar to the AdditionalLights_float one. Probably with *= light.shadowAttenuation; in the loop instead of adding diffuse lighting.
After asking that I ventured out to learn how to code surface shaders because the graph was giving me too many headaches, I'm keeping this though, for if I fail misserably
Thank you very much!
Ah okay, if you're planning to use surface shaders I'd assume you're in the built-in render pipeline which would be different anyway. My repo only works in URP
Different? assuming I am on built-in? oh god, what did I get into xD
I guess it's not going to be as straight forwards as I imagined
If you're using URP, it doesn't support surface shaders. That's the reason for my assumption
It did let me create a surface shader file, so I assumed it could be done
Although, that explains why the material was pink from the getgo
Yeah, I think the option is always there. But if you apply it to a material it'll be magenta
how can I visualize the depth buffer of the main camera in urp?
Awesome, thank you!
hello hello
How do I use a transparent video as a texture in unity URP
like I want the transparency to be used too instead of it being totally black
Greetings. Does anyone know if there is a way to do raycasts in a surface/frag shader that would collide with any mesh in the scene so that I can change thing about a pixel dependent on what information that raycast returns?
No, a shader does not have access to any information about the scene apart from what you or Unity gives it through properties/uniforms.
Okay, thanks. and I'm assuming that giving it access to every visible mesh in the scene would probably be too much?
You have to think about how you want to encode that data and how you want to use it. You could gather all the triangles of all the meshes in the scene and pass that as a big array to the shader, but then every pixel would have to loop through that whole thing to find what triangles are near it. You could encode it into some kind of spatial tree to speed things up. You could also encode it as a 3D signed distance field, this is what UE5's software Lumen does.
does anyone here knows about hdrp custom camera passes ?
But it's complicated to generate this data in a performant way
hmmmmm. Looks very interesting, but it isn't very optimized for games
how can I transform a black/white gradient into a binary output from a threshold ?
anybody using toon chan? why is outline not working in urp v12 ?
(shader graph)
is there a shader support extension for VS? Or are there other IDEs?
Not with a mesh, but you can perhaps intersect the scene itself. What you won't get is occluded things, but you can get screen-space/view-space things...AKA depth-buffer to worldpos.
Otherwise like was said above, you'd have to pass in a ton of mesh data. I've done it for a ray-tracer, but it's not anything that is for real time graphics at 30+ fps.
all the the features besides the shading step and feather settings dont work on urp 12
Yeah. I think I'm going to try a slightly different approach using extremely simplified meshes to get a similar effect as what I want. I just need a good fast HLSL raycasting algorithm that works with triangle meshes
Hey i can't find the Alpha option in the shader graph ? i can add him manually but idk he didnt do anything ?
in the graph settings you have to enable transparency
where is graph settings ? in the package ?
in your graph
Ooooo thanks!!!!
Also what is the byte equivalent in HLSL? If I wanted to send a struct with several byte variables to it?
oh also this yes this does seem to be a solution, but that requires making everything unsafe, which I dont really wanna do if theres any alternatives
http://three-eyed-games.com/2019/03/18/gpu-path-tracing-in-unity-part-3/
Also worth researching BVH acceleration structures.
lol. GPUs are weird. Unfortunately, there isn't one of a scalar type that I know of.
You can fudge it and use bitwise operators on a 32 bit uint, so 4 bytes packed into an unsigned int.
https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-scalar
SM 6.2 supports 16 bit scalars, if I read this properly, but some platforms may not. https://github.com/microsoft/DirectXShaderCompiler/wiki/16-Bit-Scalar-Types
and IIUC Unity isn't supporting 6.2 yet.
this is exactly what ive been trying to do for the past like 6 hours
but CPU or GPU, I cant get my uints to align with bytes, get modified, and return the correct results....
OK, I have to ask...
Is your storage space that limited, data size so big, that you can't take the easy road and just use good 'ole ints or uints? Yeah, you waste space a bit. But how big is big? What if your target platform has 4 GB of memory or more?
no its the way it is so it can be very very quickly retrieved on the GPU if theres 30k instances of it
The GPU "likes" things aligned on 4 byte boundaries FOR SPEED reasons, and memory access. I get that bandwidth is a concern too, but somehow that is a bit beyond me, they like and are optimized for 4 byte boundaries....actually I think they like 4x4 (16 byte) boundaries best. Like stuff all data into float4s where possible. I've heard that somewhere before.
mhm thats why its formated into uint's that I then pack into uint4's
Cool, so what's not working?
Also remember that things may need atomic operations if multiple thread write to the same area at the same time.
BTW, I'd use uints on the C# side too.
sorry internet went down for a bit
Overall whats not working is getting the correct results to match up with the results from a more gpu friendly approach and I have no clue why
The first thing I'd do (and maybe you've already done it) is to create some benchmarks and test hypothesis that it's faster with the bit shifting/masking rather than addressing 30K expanded data.
But OK, let's assume it is faster to pack it all in, so you should be able to pack it all into uints on the C# side, and then unpack it and work with it as uints in HLSL, write it (again shifting and anding, maybe with atomics if needed) and if necessary read it back (but readback is slow from a GPU compared to write).
I have to bail out for the night, I'm up at 4 am....:(
fair enough but thats what I have been trying to do
its all fun and games until I get to the writing bit, then the values are not the same D:
I was wondering if someone could help me with some shader trouble I've been having. I'm pretty new to game development/unity so im sorry if this is very basic. I found a asset on the unity store that creates a fog effect in the world scene. I was having a lot of trouble implementing this since I can seem to only put shaders on actual objects, rather than on like a players camera or somehow just in the map. Would anyone be able to teach me the write way to go about these things and shaders in general? thanks! here is the link to the asset I was using: https://assetstore.unity.com/packages/tools/ui-shader-with-fog-195773
Thanks!
How do I make an intersection shader in unity 2020? I've followed all sorts of tutorials but the band around where the objects intersect changes width and position as I move the camera, and I'd like it to stay constant relative to the object
Hi, not sure if this is right place to ask this. Does MaterialPropertyBlock not have a method for checking if a property exists, like Material.HasProperty()? Or is it standard to just use Material.HasProperty() for these checks?
why is my outline not showing? i upgraded from 2021.1 LTS to 2021.3 LTS und now my shaders are slightly broken
why do they even call it lts if you cant use any of your shaders after upgrade??? what a mess
then check the material that propertyblock inherits from
materialpropertyblock is not a material, its just an object dependent override for material property
but you can check if materialpropertyblock has an override for a certain property https://docs.unity3d.com/ScriptReference/MaterialPropertyBlock.HasProperty.html
This is interesting too
http://raytracey.blogspot.com/2016/01/gpu-path-tracing-tutorial-3-take-your.html
Yup, just found out that this exists, but only in Unity 2021.x and later. We're using 2020.x, hence the confusion. But we plan to upgrade versions anyway, so this shouldn't be an issue anymore. Thanks 🙂
Im having trouble with shaders that use the depth pass on some mobile devices. Is there some devices/GPUs that dosent support it?
Im using forward rendering in URP
Shader "Outlined/Silhouetted Diffuse Texture" {
Properties{
_Color("Main Color", Color) = (.5,.5,.5,1)
_OutlineColor("Outline Color", Color) = (0,0,0,1)
_Outline("Outline width", Range(0.0, 50)) = .005
_MainTex("Base (RGB)", 2D) = "white" { }
}
CGINCLUDE
#include "UnityCG.cginc"
struct appdata {
float4 vertex : POSITION;
float3 normal : NORMAL;
};
struct v2f {
float4 pos : POSITION;
float4 color : COLOR;
};
uniform float _Outline;
uniform float4 _OutlineColor;
v2f vert(appdata v) {
// just make a copy of incoming vertex data but scaled according to normal direction
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
float3 norm = mul((float3x3)UNITY_MATRIX_IT_MV, v.normal);
float2 offset = TransformViewToProjection(norm.xy);
o.pos.xy -= offset * o.pos.z * _Outline;
o.color = _OutlineColor;
return o;
}
ENDCG
SubShader{
Tags { "Queue" = "Transparent" }
// note that a vertex shader is specified here but its using the one above
Pass {
Name "OUTLINE"
Tags { "LightMode" = "Always" }
Cull Off
ZWrite Off
//ZTest Always
ColorMask RGB // alpha not used
Blend SrcAlpha OneMinusSrcAlpha
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
half4 frag(v2f i) :COLOR {
return i.color;
}
ENDCG
}
}
Fallback "Diffuse"
}```
How can I make this shader add outline but not change the picture made by the shader which worked with the mesh previously on this frame?
Is it even possible?
Yo so I just started using unity a few days ago so if i say anything hecka dumb excuse me, anyway i want to make a shader graph for my 3d game im working on, but whenever i go to create it and look under shaders I cant figure out what to do to create a shader graph, like it just doesnt show up, is there something I should know?
URP Lit - I'm using the checker noise to make a simple checker texture, is it possible to avoid to stretch it while scaling the object?
try adding connecting the position node to the noise node?
i'm not sure
Not working 😐
or it kinda does
works well on some faces
maybe this is sue to the other problem I'm currently trying to resolve
the issue is that on some faces the checker is not visible
idk
if only unity wrote down what each node does
it's too confusing to read sometimes
Doesnt the node library do exactly that?
some nodes aren't descriptive enough
they need to show examples and show what they do
Two things I can think of. You can either "unscale" the texture by playing with the tiling & offset node setting values as a function of the scale maybe including object-space values because you need to decide what plane you're messing with, or you can look up and apply triplanar mapping.
Can I go the triplanar way by using the chekerboard node as texture?
The checkerboard node can be thought of as a texture sample based on the input UV (and other things like color and scale).
It's actually just math. No need to even read a texture, even better.
I think I've set it up correctly, now I'm trying to find why I cant see some sides of the shape
Is it a mesh cube or what?
its a default cube
I also tried to delete everything from master and still get that issue
Now that I'm testing could be due to the absence of light
Ok I can confirm that by rotating the light source that texture become visible on the faces
now the question is: how can I make it not (or less) light-dependant?
Here's the shader file if somebody want to see the nodes
Hi peeps! Shader question that i can only describe as inheritance 😛
I want to make a shader that extends the Standard shader.
It would look to the tune of
float4 frag (v2f i) : SV_Target
{
float4 standardColor = base.frag(i);
if(distToVertex(i) > _MaxDistance)
return standardColor;
float4 effect = CalculateOwnShader();
return Blend(standardColor, effect);
}
Idea being the material shader effect only comes into play within a certain proximity.
Any thoughts?
I Try Reconstruct the world space positions of pixels from the depth texture
but screenView is different from GameView
{
float2 uv = UnityStereoTransformScreenSpaceTex(i.uv);
// uv = i.pos.xy / _ScaledScreenParams.xy;
float depth = SampleSceneDepth(uv);
// Sample the depth from the Camera depth texture.
#if UNITY_REVERSED_Z
depth = SampleSceneDepth(uv);
#else
// Adjust Z to match NDC for OpenGL ([-1, 1])
depth = lerp(UNITY_NEAR_CLIP_VALUE, 1, SampleSceneDepth(uv));
#endif
float3 worldPos = ComputeWorldSpacePosition(uv, depth,UNITY_MATRIX_I_VP);
float2 projection = worldPos.xz;
if(_ProjectionEnabled == 1) projection = mul((float4x4)unity_WorldToLight, float4(worldPos, 1.0)).xy;
float2 uv_clouds = projection * _CloudParams.x + (_Time.y * float2(_CloudParams.y, _CloudParams.z));
float clouds = 1 - SAMPLE_TEXTURE2D(_NoiseTex, sampler_LinearRepeat, uv_clouds).r;
color = clouds;
color = half4(worldPos, 1);
}```
my code hope for help and @topaz cipher 😦
what is the world space view direction?
World and View are seperate spaces, i don't understand
could i get some assistance with the order of operations tto replicate that
View direction means the direction from the camera to the fragment.
yeah, that's right
is this person transforming the view direction into a world-space one? i'm not ssure what they mean
I mean the direction from the world position of the camera to the world position of the fragment
So it's world space
ok, so simply the view direction in other words
i'm not sure exactly where i'm going wrong in trying to replicate this effect
i've got my cube here in the normals view
The view direction can be in any space, so I wouldn't call world space the "default" space for view directions
so i'd anticipate purely blue pixels because positive Z (or is it negative Z from view, not sure)
since if the pixel normals all faced the view the object should be purely blue yeah?
for sure just assigning the view direction to the normal doesn't work because that makes results like this
Why are vertex function and fragment function separated instead of being a single function?
Are you sure you're setting the world space normal? It might be setting the normal in tangent space, like when you apply a normal map.
not that you need shader graph to do this but here's what i've got in shader graph
the vertex normal is being set to the view vector
i guess i'm not quite getting what the person in that post is doing, it doesn't seem as simple as what they made out
this approach is 'world space view direction', see that all pixels of the cube have normals the same
but this isn't right either, i shouldn't be able to see the shine from this angle
since the retroreflector is meant to send light back along it's initial path, not bounce it up to be seen from here
i'm a little stumped
Hello, how do i make an additional texture on top of main texture? Kinda like stamp
thank you
does BRP have a normals overlay view
that shader was made for BRP so I can't even see the normals view on what it's supposed to look like ;-;
No, but you can edit the fragment shader to output the world space normal as the color
@low lichen
i have done this now
so here's the comparison of the one i found in the Answers post
(normal mapped to albedo)
and then mine
they seem to match? so i don't know what i'm doing wrong
okay so with the help of a new project i determined that the shader in the answers page is actually completely broken
and presumably the advice he gave is also incorrect
so in that case i've got no leads at all on how to achieve this effect
his solution only works for the positive Z
ok so yeah im clueless i guess, this sets me back to the very beginning
i gotta ask if anyone has made a retroreflector and how they did it
How can I make so the checker texture doesnt get stretched? I've already tried to put the Position note on its UV but doesnt works...
what are tiling and offset in a material?
Hello, I made a 2D shader that adds pixels in an area bigger than the original Image. How can I make sure that it will not be cut by the sprite bouding box ?
expand the bounds
how can I do that outside of the original image bounds ?
you can set it to whatever you want
It's a UI image
Will it work for a UI image ?
I don't see why not
a UI image is not a Renderer
You'd likely need to scale down the original image. Assuming it's centered, should be something like (uv - 0.5) * scale + 0.5 iirc. May also need to mask it to prevent clamping if the edges of the texture aren't fully transparent.
Then scale up the vertex positions (in the vertex shader stage), or just scale the UI component.
okay
I'm currently trying to use a bloom material on some mushrooms but it isn't quite working
this is how it should look (+ bloom)
and this is how it looks when i apply the material
the shader graph is rather simple, so im not sure what i might be messing up
there are multiple types of mushrooms and they're all in the same spritesheet, is that a problem with maintex or something?
You need to connect the A output from the texture sample to the Alpha port
Following this tutorial: https://www.youtube.com/watch?v=3Ccu3UtiSdw
Now you can easily add a Retro feeling to your game with this cool Shader Graph and Render Feature combination. With a few Post-Processing effects on top and that's it you got yourself a CRT / Old TV feeling. Enjoy!
Pixel Art Tutorial: https://youtu.be/JZDlCuIpq9I
Cyan Blit Render Feature: https://github.com/Cyanilux/URP_BlitRenderFeature
✦Rab...
Gives me a fully grey screen
Is there a better way of creating a shader with the frame as an input? As in, I'm trying to cell shade a fully rendered scene
Hey guys. I'm working with "NOT_Lonely/NOT_MaskedPBR" shader and it seems to be doing some funky stuff with the lighting and light cookies.
if I have an object with multiple children objects that all have particles is it possible to apply a shader to the entire parent object(like an outline effect)?
Hey everybody! I am trying to make my player cast 3d shadows, but although it is effected by light its not casting shadows
Anyone here have an understanding of how URP decals in shader graph work? I'm faking some shadows with decals and trying to change the render queue on them to render before my emissive materials (so shadows don't appear to wrap around emissives) However the decal shader graph option doesn't seem to allow render queue changes in the graph or on the material. Any ideas?
im doing an NES style of game where I want to use a color palette and replace certain colors on an image. Does anyone recommend a shader or asset on the store for this?
welp, doing it by hand 😄
does Unity have an Object type for Shader Graph assets?
example, if I use Shader x = AssetDatabase.LoadMainAssetAtPath(someShader) as Shader; then X will be loaded as a Shader
but is there some type for ShaderGraphs?
Does just Shader load it? Because it should...
I'll have to test some more, perhaps it actually does, and it is shadersubgraph assets that are not.
thanks
Sub graphs are SubGraphAsset
So I'm very new to shaders, and I want to try and do this:
-
Get a list of colors externally
-
Make an array of those colors
-
and for each pixel:
take the base color, compare it to each of the colors in the list, take the highest value of the comparisons then do something with that.
So I'm good with the actual colors part, I know how to do what I want for two colors individually. but I don't know how to make a list of colors and loop through it, in HLSL anyway.
I know you can define public variables in the properties section of the shader, but I'm not sure how to make an array there, if you even can.
You can use a texture. What is a texture but an array of colors really
huh. good point
I'll look into that, thanks!
how would I loop through the texture though?
please forgive what im sure is a super newbie question, but this keeps throwing up the error sampler2D object does not have methods
I don't understand what I'm supposed to put here, I've tried putting a bunch of stuff and they'll pretty much always throw the same error.
the documentation says it needs a sampler state, maybe i'm just dumb but I cannot figure out what a sampler state actually is
I can't seem to find a straightforward answer
I haven't figured out the necessary vector math for it yet either
But I did notice that lit particles that face the camera can be used as a ground truth or a placeholder for retroreflective things
yeah true
Pretty sure this method works
differs from the particles a bit because particles seem to reflect the sky, not the baked cubemap, at least in my test currently
well the problem is still fundamentally that the reflected light is being reflected by the angle of incidence instead of 180 degrees
Right, this wouldn't be perfect at angled lights
is there way to like
make the normals not normalised?
cos if you made the magnitude of the normal like
idk 100
then in the vector math
the angle would be more advanced towards the camera position maybe idk
@arctic flame I dunno why I put world view direction to object normal, but it seems to work perfectly well with any view direction to matching normal
At least I can't tell just by looking if it's not physically accurate, though I doubt it is
what's it look like in like a turn around?
ohh yeah ok this is interesting
i noticed you did it to the fragment when i was trying to do it to the vertex
i don't really know the difference i suppose
Seems to work the same both ways with this setup
should you do both at once?
I don't see a reason to
If you can get by doing it in vertex stage that's probably cheaper
But you may need to do it in fragment stage anyway if you want to combine it with normal maps, not totally sure
that's sick though
Anyone? Im quite clueless as I have "Cast Shadows" set to active
I don't think SpriteRenderers can cast shadows. You'd need to use a MeshRenderer on a quad instead.
I thought that was part of the base renderer which sprite renderer inherits from
I figured out a solution XD Just had to turn on debug and check cast shadows which is inherited from renderer
Hmm, they both inherit from Renderer. But that does seem to have the shadowCastingMode which you might be able to force from a script
Ah yeah, or debug inspector
thx though ❤️
Hello, does anyone know how can I reset shader on instantiate.
I have a dissolve shader (brackeys tut), but when I instantiate the gameobject dissolve effect is finished so it never shows, is there a way when I instantiate an object to play that shader effect from start?
You should be instantiating a prefab, not your object from the scene
That's what I'm doing, but all prefabs have like global time where the dissolve effect is happening.
And it has Time node going into a remap
Instead of the Time node, use a Float property. You can then have full control over when it dissolves (and the speed it dissolves at) from a C# script, via renderer.material.SetFloat("_PropertyName", t)
Good idea, I'll try that. Thanks @regal stag
Hey guys I'm using this plugin to make a gameboy look for my game, but the problem Is I can't figure out how to set the resolution to 1920 x 1080, does anybody know the fix? https://roguenoodle.itch.io/gbcamera-for-unity
How to see sphere from the inside? Can I do it with some fancy shader trick?
I'm currently using the triplanar node in urp and noticed that faces that are not flat have a sort of ghost/overlap effect on them. Any way of fixing this?
Might just ditch the triplanar and spend some time mapping the scene correctly
Triplanar mapping will always have some ghosting if the face is not perfectly aligned with the projection orientation
that works fine for noise like texture or structures but not for textures like your test pattern
Hello! I've done (actually copied and modified a bit) this shader from a youtube video:
It is used to apply two different textures on a terrain, and it chooses which one to draw based on the height.
It also smooths the border between the textures:
Now, I've got a dilemma: how can I do the same thing but based on an array of data? I can pass an array to a shader using a color array, but I have no clue on how to do the same effect I'm having there with that color texture.
I need to do it to create different biomes and to change the texture in a point of my world at runtime.
Does anyone know how to target different mesh topologies (MeshTopology.Points) via shader graph? If I script a custom mesh using the point topology setting, I'm getting an error in shader graph (missing PSIZE output).
It's been super hard to find resources on how to use those different topology settings.
Shader graph does not have support to do this afaik. Though you could generate shader code from the graph and then edit that further. (There's a button to show the generated code in Unity's inspector when the graph asset is selected)
Ah, I was afraid of that. Thanks for the confirmation though - that'll save me a bunch of time chasing a dead end
Perhaps instead of passing a colour array, you could generate a Texture2D at runtime (e.g. https://docs.unity3d.com/ScriptReference/Texture2D.SetPixels.html)
Well, yeah, that's what I meant: I create a texture from a color array
Then I pass it as a texture to the shader
And I basically got an array with the values I want (the texture is an array of pixels)
Which shader should I use in my bullet trail material to fix it being pink?
Any shader that's actually supported by your chosen render pipeline
Is there a way to check?
Check what
That which shaders would be supported
This far ive blindly tried everything and none of them seem to work
which render pipeline are you using
Id guess the built in, havent changed anything other than colorspace
DOn't guess
check
you should know which RP you're using...
you picked it when you created the project
and it will be that unless you changed it
Okay so built in, it also says so in my "graphics" tab
ok then the default Standard shader will work
Then my problem lies elsewhere
by this you mean there's no SRP asset assigned in graphics tab?
Alright I fixed it, was a different problem altogether, nothing to do with shaders
Every dropdown menu said "built-in"
that's not really a good way to indicate if SRP is active or not... you should just check the SRP Asset being assigned or not
I mean even if you'd have URP active, it would show this there
Yeah it just says "None"
yeah that's fine then
out of curiosity, what was it?
(the issue that caused this)
I had my playmaker script creating a bullet prefab, that for some reason was not pointing to the right prefab anymore
So just me being a newbie 
So, the bullet created had the trail renderer, but hadnt had the material set on it
also surprised people still use playmaker 🙂
Its just what I used 5 years ago when I last did any projects
Works for a hobbyist 😛
ah, so you aren't all that new to this 😄
yeah, 5 years sounds accurate, playmaker used to be really popular
Yeah but its a good excuse when you make dumb decisions and ask help publicly 
probably harder to get help with playmaker issues nowadays in general
but whatever works 😄
A little bit, but its super easy most of the time so rarely need help in anything that-related
Still fascinated:
This video demonstrates how simply we can use 2d maps and generate detailed 3d. I made a few gradients in photoshop using the square gradient tool. This allows to create a pointed tip and fades out in a square/diamond.
With varied scale and color levels of the same gradient, I exported a black and white displacement map. This map was applied to ...
hello
I was follow this instruction, and using Universal render pipeline
there is a property that can be added, one of them is a property called float
but, this property type doesn't exist in my place
But, I still think now it's vector1
Which Unity version and Shader Graph version are you using?
7.4.3
Unity: 2019.3.6f1
Okay, that makes sense then. They just changed the name at Shader Graph 10.0
Hmm
what name ?
Unity just changed the name of Vector1 to float, but the functionality is the same. So the tutorial you're following is just using a newer version of Shader Graph.
hmm, So, the new version of shader graph is in 2020, because my unity, 2019, is the higest one, (which is 7.4.3), and no higer version is shown
however, I guess everything is still fine, then
Yeah, it should still work
Anyway, thanks for the information.
I know this might be a lot to look over, but if someone with some shader graph knowledge is willing to help me out, I'd really appreciate it!
I'm working on a grid shader, and everything is working great except for transparency. I have 2 colors (one for outline and one for the base color), and I'd like each of their alpha settings to have their own transparency (if that makes sense). Right now, whenever I set this to Transparent, it just becomes completely invisible regardless of either color's alpha setting in the inspector. Any ideas on what I'm doing wrong/need to change?
So, Question
I got this
and the warning says
the active master node is not compatible with the current render pipiline or no render pipeline is assigned
nevermind, I found out the reason why
Nvm this too, I also figured out the problem haha
Changed it to this. I realized somewhere my colors were getting set to (3) instead of (4), so I had to work around that like I did in the screenshot below. Now it works perfectly.
Would anyone know how to dilate an image in shadergraph?
I'm not sure how it'd be possible to dilate an image using just shader graph, but it's probably a better option to generate an SDF from the texture using a tool such as this
https://assetstore.unity.com/packages/tools/utilities/sdf-toolkit-free-50191
SDF textures can be dilated/eroded using step or smoothstep nodes
hmmmmm..... Maybe Gaussian blur and using step()? Or you can shift along 2 coordinates and apply the texture as in a gaussian blur, but do not apply the blur profile
A blurred texture can be used similarly to an SDF texture, yes, but loses some detail
I believe both operations are pretty expensive to do realtime
If you need it for letters, then you can actually use TextMeshPro built into newer Unity versions, it generates a SDF Texture for the whole font, used for font style and outline
this would be better if it has to be dynamic real-time https://bgolus.medium.com/the-quest-for-very-wide-outlines-ba82ed442cd9
Skip to the jump flood part
I'm trying to make a custom low poly water shader, I need to flatten the normals on this outlined plane, how would I go about this? (I'm coding it not usign shader graph)
Hey anyone there who could help me combine a crossectionshader with a watershader? I'm stuck - It's hlsl
cause I'm stupid☝️
I have no idea how to even make it transparent - cause if I set it to transparent on the material's options it's still grey
I'd even drop some bucks if anyone could help me remotely....
How can i make the noise not stretch
this should work, just sample the heightmap (or wave texture, whatever you use currently), and just pop it into the normal() formula at the end http://www.dian-xiang.com/blog/2 and then call normalize() on it to make it's lenght 1 as normals should have
here's one with a scaled heightmap (ignore the if cases) https://www.flipcode.com/archives/Calculating_Vertex_Normals_for_Height_Maps.shtml
Alright, I'll try that when I get home, thanks
nvm i just needed to use 3d noise
This does work, but you may save a lot of performance by using Triplanar node to project the same noise from different axes
And even more so by using a noise texture instead of a noise node
I'll try that in a second, my friend is rendering a noise texture for me
why does it not fill the entire space
only 1/4
The Tile input is used for scaling the texture
Noise textures must be seamlessly repeating to seamlessly repeat (though that's also an advantage in many situations compared to noise nodes)
Everything in what way?
The entire quad
Triplanar repeats the texture over the whole mesh
Tile input is used for scaling the texture as I said
does anyone have experience sampling an sdf inside a custom function node? Most documentation I found uses data type sampler3D but the node only allows you to pass a 3d texture, so how can I sample it?
That icon morph thing is really cool, i can imagine quite many ways to use that in loading screen animations for example
Appreciate the article @meager pelican , visualizations are always really helpful. I'm working on creating a volumetric shader and I need to sample a 3d texture I created with the sdf bake tool.
It's really nice
I don't know about 3D SDFs in shader graph though
Oh, I thought your problem was you DIDN'T want a 3D sample.
If you have a 3D texture, what's the actual problem, again?
Yes exactly, input param of type sampler3D but in a custom function, only 3dTexture or UnityTexture3D is allowed. How can I create a sampler from a texture within HLSL?
Shamelessly copied from: https://docs.unity3d.com/Packages/com.unity.shadergraph@7.1/manual/Sample-Texture-3D-Node.html
float4 _SampleTexture3D_Out = SAMPLE_TEXTURE3D(Texture, Sampler, UV);
So you need a sampler, yes?
Maybe generate a code sample using the sample3D node, and see what it does?
UnityTexture3D should also include the sampler, via .samplerstate
copying the generated node code is smart, do you know where I can find the documentation for these Unity object types like UnityTexture3D?
The only thing I know of is Unity's shader graph docs, and the repository where you can dig through code.
There's a mention of the texture types at the bottom of the Custom Function docs page too https://docs.unity3d.com/Packages/com.unity.shadergraph@12.1/manual/Custom-Function-Node.html
Ok thank you both, the method calls are equivalent float4 Sample(UnitySamplerState s, float3 uvw) { return SAMPLE_TEXTURE3D(tex, s.samplerstate, uvw); }
Hi, I am following the official tutorial on shader graph, in which I need to output an alpha channel from 2d texture asset. However, the alpha channel is gray when I try to connect them... How can I fix this? Any help is appreciated! --Using URP unlit shader graph
You need to set the shader to be transparent or cutout/alpha clipped
In the graph inspector, under graph settings
Check it out, I was able to render the sdf of a mesh inside the volume of a cube mesh
Looks sweet!
Hey so i'm writing a shader in Shaderlab language and I've written a couple of simple utility functions, i'm now writing a second shader and want to use those same functions, can I make some kind of shared include file?
if so.. how 
I believe it works like any other language where you import the module, in this case #include <filname> https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-appendix-pre-include
does the file need any kind of special directives? the normal file has a lot of preprocessor stuff i dont really understand
Hmm, it looks like you need to declareexport myFunc() { ... } to link it elsewhere. Without looking at your code, I would suggest pulling the utilities into a separate file and import that file. https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-appendix-keywords#export
i've been slowly learning shaderlab by trying to recreate some of my blender shadergraph shader nodes
i'll see if this works 
Shader error in 'Custom/SkinShader': Unexpected identifier "export". Expected one of: typedef const void inline uniform nointerpolation extern shared static volatile row_major column_major struct or a user-defined type at Assets/Shaders/util.cginc(1)
oh do i not use export if im using just include file

oooh that works, ty
The #include should just "paste" the file in. It's equivalent to a copy/paste from the file's contents...without actually duplicating it in every file.
Does anybody know how to write URP unlit shaders to depth-buffer?
I'm using amplify shader editor
I think Universal/Unlit Shader Template doesn't write to Depth buffer. So the unnecessary parts gets effected by the dof effect.
Just like on the top left corner.
This is the depth texture from frame debugger btw
Pretty sure nothing writes to depth buffer by default, but you can turn it on with ZWrite On , or checking the box in shader graph. Never used amplify before and I don't understand the effect you are trying to create
I think it already is
What is the fog-like bloom in the image above?
Are you talking about the clouds in the scene?
They are just transparent planes with vertex offset
Aha, it throwed an error. Maybe this is why?
Problem is these objects, they are using an unlit opaque shader.
the shader error was thrown in a Lit shader by the looks of it
Yeah but not sure how amplify structured the shaders, they might have a fallback or something? Just some random guess.
Yet I don't think the error is the problem because the shader mostly works in right way.
If you give those blue silos a different shader does the problem go away?
I'm confused why the brown part is causing a chop in the silos
They are all connected to one material for now
The others arent blurred because they have placeholder floor after them
the floor is using default material
So it writes to depth buffer
Just like what this ss shows.
so are the silos not separate meshes?
No, they are not
oh
We are playing with new artstyles so they are just some placeholders.
Which causes this chaotic shot :)
not sure I can help 😦
No problem, thx for trying
so im using SurfaceOutputStandardSpecular for my output struct, how can I do what blender calls "Specular tint"
does this property have a different name? 
Any tip how to achieve this? It's ID to Color shader. Not sure how to handle syntax
fixed4 frag(v2f i) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(i);
float ind= UNITY_ACCESS_INSTANCED_PROP(Props, _Id);
fixed4 color;
color.r =(fixed) (ind & 0xFF);
color.g =(fixed) (ind >> 8) & 0xFF;
color.b =(fixed) (ind >> 16) & 0xFF;
color.a =(fixed) (255-(ind >> 24));
return color;
// return UNITY_ACCESS_INSTANCED_PROP(Props, _SelectionColor);
}
i really need help rn with a transparency code in my game, i didn't change it one bit from the other game i had it in where it works perfectly fine, but in this other game it doesn't work at all, it is supposed to make the black solid color of the camera's view completely transparent to show the desktop, but it won't, and i covered all the bases to make it happen too
ok seriously, i need help from someone on this i'm losing it. it isn't even the code and i have the transparency settings as a full window, the bottom check ticked as disabled, and no custom pipelines, and the camera has no background and yet it just won't work
hello hello, How do I use a transparent video as a texture in unity URP?
like I want the transparency to be used too instead of it being totally black.
If your video format has transparency, it should just work like an other transparent texture iirc.
Hya. I'm running into a little issue with shadergraph I cant seem to work out
I'm generating these lines (rectangles) and trying to overlay them on a texture
I've tried all modes for the Blend node, but the Add node seems to give the best result, but Only for white shapes.
other colors get different opacity, as you can see
How do I correctly do this. So overlay the rectangles on top of a texture, with no opacity?
easiest way would be to have a mask (with only black and white colors) that you can use to lerp between those two (texture and the procedural lines). hard to tell how to do that exactly without seeing how you get the those lines
Thanks! How would you lerp it? T is a vec4 on the Lerp node
0.5 for all channels?
if you put single float in float4 slot, it will just copy the same value for every channel. for example if you put 0.25 in float4 slot, you get (0.25, 0.25, 0.25, 0.25) as result
This is how the lines are generated btw
so here you would have the mask right?
Yeah, goes to this
you gotta put the 2 options in A and B and put the mask in T
Ahh, Thanks! it works, awesome
and now I can control the opacity through the channel mask
masks are super useful when you want to combine different things together
yeah, thanks. finally got my shader working then, great!
np
How low are Line Renderers?
Would something like 500 of them be considered a lot? I assume they got more intensive the longer they are.
?
hey everyone, I'm trying to make a custom shader which supports transparency texture
I made everything else I wanted to work, but the transparency is the only part which gives me a headache
Could anyone help me out with this?
Im not sure if thats shader related, #💻┃unity-talk would be better. Anyways, its hard to tell. That shouldnt be too hard to test. You can get rough approximation of the performance really easily by making line renderer of lets say 10000 points and randomize them using code. You can watch the fps to see how it performs
Sure, have you configured the texture correctly? There are different settings you can apply in the inspector. For instance, if you import a png file, you can set transparency source.
Hi, im trying to convert a Godot shader to Unity from a tutorial video im watching, and they use the code snippet:
which uses the variable VIEW, which in Godots documentation means the View vector under its lighting section
i was wondering if Unity had a similar function, as I cant find one under unitys shader documentation
might just be view direction
what is that called in-shader?
Is there any updates or talk about updating to shader model 6 or ways to access shader model 6 yet?
in shader amplify there's node called "Texture Object Node", what equivalent nodes that comes as that on ShaderGraph ?
so I got this material that has its base color copy from screen space like this
however it doesnt show the TextMeshPro behind it. How can I solve this?
The shader itself has alpha as well
I changed the order of shading and I think it works now
I'm getting the error "array index out of bounds". I'm not using arrays in my program though, so I'm not entirely sure what it's talking about. The only think I can think is that it's mistaking something for an array? I'm using matrices and referencing them with matrix[0][0]. Additionally, I'm referencing float3s like float[0].
here's the full error
Posting your shader code would probably help us help you
Hello, does anyone know if it's possible to include custom tesselation into shader graph? I know you can include custom buffers/function/data structures via .gcinc files via the "Custom Function" node, though don't know how to do it for tesselation at all.
2021 lts shoulr have tesselation support for hdrp https://portal.productboard.com/unity/1-unity-platform-rendering-visual-effects/c/56-tessellation-for-hdrp
@mental bone I'm looking to make custom tesselation for the terrain. Phong tesselation, which is currently included in the shader graph, causes severe clipping issues for physcis on a quad based heightmap terrain.
Im not sure you will be able to do that with shadergraph
Im also not sure how you will get a terrain collider at all out of the tesselation since its a purely visual step that happens on the gpu
in Shadergraph is there a way to fill in the clipped area with a color or texture?
I can turn on Two-sided, which sorta does the job, but is there a way to selectively change the backfaces with a different color or texture?
my very basic set up atm
I can find lots of resources online of people saying 'turn on two-sided' but no one saying how to then change how the backface looks
this could all be an x/y problem, what im really trying to do is cap off the cutaway area
There is an Is Front Face node that you can use with a Branch node
I see, thanks that helps!
Hmm, how do I combine multiple clipping directions?
I tried a few math like add, subtract, multiply, but instead of clipping on multiple axis, it just combines them and the resulting clipping plane gets rotated
shaders are hard, I can easily describe verbally what I want to achieve, or draw it, but I have no idea how to make the nodes and math to achieve it
I want to clip away meshes between the camera and the camera's orbit point
I can clip on any one single axis globally, but I can't figure out how to combine multiple clips to create an L shape
and it wont necceessarily be on xyz perfectly either ,its got to rotate but thats a later problem
I cant find any tutorials for this though and ive been googling a lot
How do you clip away from a point in world space? not a flat clip but imagine an L shaped cut away
my attempts to clip on mutiple axis don't seem to work, it wont clip on more than one axis
The Alpha Clip Threshold is a Float port, so you shouldn't really be putting a Vector3 into it. It will only be using the R/X value
Is it possible to clip away an L shaped portion of a mesh some other way than Alpha Clip Threshold?
If you want multiple planes try using Step nodes and then combine with Multiply, or Min/Max
Do I still plug it into the alpha clip threshold at the end?
Yea, or Alpha and set threshold to 0.5.
It clips if threshold < alpha
I am not sure where to insert the Step node into my setup
Googling it Im not even sure how to use it at all
What is my Edge? I assume the clip space is the In
I am not seeing how a single value like R/X is going to be able to cut in 3 dimensions
Progress 🤔
Hm this isnt right, no matter what values I feed it, it wont clip anything at all anymore
it works in the preview, it doesnt work on the real deal
yeah no matter what values I feed it, it wont clip
I think im just too stupid to do this, I should stop trying to do things im too stupid to do
this isnt good enough or anywhere near what I need but its all I can do :/
I keep googling "clip on multiple axis" and similar terms but I cant find anything
no help, no resource, no tutorials
all the tutorials are for totally unrelated useless stuff like dissolve shaders or 'cut a hole in this thing based on camera / player data'
I dont want to dissolve or cut a hole, I want to clip away everything around a point infinitely
like imagine this is 3 infinite planes all moving away from that intersection point, clip away everything
what terms should I be googling?
I keep trying clipping or clip but its not returning results I need
I hate how stupid I am, i can never achieve anything without someone bottlefeeding me every single step
im such a stupid worthless hack, ill never achieve anything of any worth or value, all I can do is fail to imitate everyone who is better than me, who are too busy being better than me to extend a hand to a worthless piece of shit like me
i keep trying and trying and trying and failing I and I keep reaching out but no one can help me, or no one wants to help me, its just radio silence :/
no one wants to help a worthless piece of shit like me because they gain absolutely nothing but helping a worthless piece of shit like me, I will never ammount to anything
i dont know how to be MORE direct, MORE CLEAR
HOw. To. Clip. Model. On. Multiple. Axis
zero reuslts, tons of results for completely innane unrelated things
im fucking miserable and frustrated and angry
this proves its possible, someone is doing 3d spacial clipping here
so why I cant find a single resource explaining how its done
tons and tons and tons of clipping PLANES but not a single resource on clipping any other shape
Is it the right place to ask about render passes
I dont know, this is shaders isnt it, I need a shader to do this
What do you want to do?
I think you are looking to clip things spherically. Like in a radius ?
Not sphere, cubic, I want to clip away a cubic area
I just hit upon the word 'cross section' which seems to be giving new results
I don’t know if you program shaders or use nodes. But there is another term called SDF = signed distance functions
example of what I mean
yeah I am familiar with SDF
I dont know how I would use it in relation to a shader though
You can try looking that up as well. Because using sdf you can add specific mathematical ops and render or clip out in 3d
But for that you might want to sue a custom node or write your shader
I learnt about it while I was looking at making clouds. It uses ray marching
You March a ray from the camera and till the time that the sign is not negative you keep clipping
Btw there is a hack you might want to try
If it’s cubic, why don’t you use stencil buffer with an invisible cube. Use the cube to mask out the area you want to clip and use stencil@buffer to clip that area
Then use front and back face separation for adding specific textures… what say? @tight phoenix
still getting no where trying to do this https://cdn.discordapp.com/attachments/669975874455732224/976220175168839730/unknown.png
how do you describe this
what words do you use
cross section is wrong
clipping cube is wrong
nothing I try gives me any answers or any results
i keep trying and trying and trying and im not getting any results and im getting so fucking frustrated
is this not a solved problem?
i am not the dfirst person on the planet to want to do a cross section on more than one axis
i dont want a single plane cross section
why cant i find a single resource, tutorial, anything at all discussing this
does no one here have any idea or clue at all how to do this?
cutaway is wrong
am i just not worth helping?
what do i have to do or say, how much do i have to grovel and beg before im allowed to he helped?
i cant do a fucking thing on my own because im a worthless piece of shit, i ghet it, are you happy now? now will you help me? how much more put down do i have to be?
i guess despite there being several thousand people online, im not worth a microsecond to a single one of you :/
clipping cross section cutaway shader 3D ~cube -plane -simple -flat
no results
Working on getting Keywords to work on the Universal Render Pipeline/ComplexLit shader and finding they may be broken in Unity 2021.3.2f1? Could use some thoughts on this one - thanks all!
https://forum.unity.com/threads/material-setkeyword-and-enablekeyword-for-complexlit-shader-do-not-function-in-unity-2021-3-2f1.1282946/
I can't build my project after I added my shaders to "Always Included Shaders". Does anybody know how to solve it?
does anyone know how stencil values are stored in unity's depth buffer? like, if i sample the depth texture they should be encoded in there somehow right?
Stencil values are stored in the stencil buffer
@tight phoenix you done that man. Just use stencil buffer with a cube.
https://docs.unity3d.com/2019.3/Documentation/Manual/SL-Stencil.html
from what I understand, theyre the same thing though? like if you make a 32 bit buffer, 8 of those are stencil and 24 are depth
Guys! Someone needs to help me understand why adding passes in URP to draw rendered to a render texture doesn’t have alpha in render texture
https://docs.unity3d.com/ScriptReference/RenderTexture-depth.html
Set the format of the Depth/Stencil buffer.
@quaint coyote made a good suggestion. I've been working on something similar recently, Here is an example of the process https://www.youtube.com/watch?v=Cp5WWtMoeKg
In this coding adventure I explore ray marching and signed distance functions to draw funky things!
If you're enjoying these videos and would like to support me in creating more, you can become a patron here:
https://www.patreon.com/SebastianLague
Project files:
https://github.com/SebLague/Ray-Marching
Learning resources:
http://iquilezles.or...
yeah I've just tested and verified it is in fact stored in the depth buffer and should be extractable
Oh wait wait, you mean the alpha is saved in the depth buffer?
no, the stencil value
Oh sorry I was referring to this.
Interesting, were you able to successfully sample the depth? what was the value returned? The doc you posted had a link to GraphicsFormatUtility.GetDepthStencilFormat but it's broken 😦
Watching this
hmm i may have spoken too soon. cant replicated it now. but the data should be there somewhere since its a shared buffer.
currently i'm just testing modulos with different values and seeing if the noise changes 😛
Im not sure how any of that applies to what I was working on
for starters its in HLSL written scripting, which is about 50,000x harder than shadergraph
Can you explain in a little more detail what you are trying to accomplish? Not sure I can help but I like researching these things
I'm trying to get the stencil values in a single-pass postprocess shader by extracting them from the depth buffer.
the way everything is worded makes this sound very possible
You can clip a mesh with a transparent shader pretty easily, like you've already done, but meshes are hollow. Unlit shaders give you the illusion of a "fill", but if you want something to look volumetric, the only way I've learned so far is raymarching. You don't need to write the whole shader in HLSL, just create a custom shader graph node with a for loop inside. I've discovered my dinky gpu struggles with this however
if you know the depth value that's being clipped to, you dont need to do expensive raymarching.
I looked into RenderTexture type and the documentation was poor. I found this thread that says you cannot sample depth value from a script https://www.reddit.com/r/Unity3D/comments/2hdd6a/get_depth_buffer_in_c_from_a_rendertexture/
1 vote and 5 comments so far on Reddit
? this isnt getting it in a script, this is setting the buffer to an RT to use in a shader
and beside the point, that page is wrong, you can easily do a readback to cpu
I see, does this help? Depth textures are available for sampling in shaders as global shader properties. By declaring a sampler called _CameraDepthTexture you will be able to sample the main depth texture for the camera.
But then the depth value returned is in range 0-1 and the format is platform dependent. *On OpenGL it is the native "depth component" format (usually 24 or 16 bits), on Direct3D9 it is the 32 bit floating point ("R32F") format. * So convert the float to a byte array somehow and then take the last byte?
apparently cameradepthtexture is not the raw depth buffer. what I have already assigns the depth buffer as needed, though I can't seem to get the last byte of it in shader easily
it may be that what the depth buffer is internally and what gets saved to the render texture differs internally
perhaps Unity is attempting to normalize the buffer values to operate cross platform?
maybe. it looks like they do differ, and there's no way to sample the raw buffer
I still havent made any progress at all culling more than one plane at a time
clipping one plane = so easy a baby could do it
clipping more than one plane = impossible, no one can do this
if anyone has any insight, im getting nowhere
https://virtualplayground.d2.pl/crossSection_urp_examples/ proof that it CAN be done at least
this looks like relatively simple stencil comparisons
Dude I told @tight phoenix about using stencil about a few posts ago. With a link to unity’s document. Idk why it’s not working for him…
Also stencil buffer is a different buffer than depth buffer
theyre packed in the same buffer
RenderTexture.depthBuffer
Ohh… then you need to extract the bits out ?
Which means how many bits is the depth buffer that it contains stencil buffer too?
Does anyone have experience with using global textures in HLSL under Unity? Everything worked fine when using a per-material texture, but I thought global would fit this use case better. I'm calling Shader.SetGlobalTexture("_BlockTextureAtlas", textureMap); from the C# side, then the shader code is as follows:
Shader "..."
{
Properties
{
}
SubShader
{
Tags { "RenderType"="Opaque" "RenderPipeline"="UniversalPipeline" }
Pass
{
HLSLPROGRAM
#pragma vertex vertex;
#pragma fragment fragment;
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
uniform sampler2D _BlockTextureAtlas;
struct VertexParams {
...
};
struct FragmentParams {
...
};
FragmentParams vertex(VertexParams input) {
...
}
half4 fragment(FragmentParams input) : SV_TARGET {
half4 color = tex2D(_BlockTextureAtlas, ...);
...
return color;
}
ENDHLSL
}
}
}
Any help is greatly appreciated!
Things I've tried:
- Leaving out
uniform - Separately defining the texture and sampler
uniform Texture2D _BlockTextureAtlas;
uniform sampler2D sampler_BlockTextureAtlas {
Texture = _BlockTextureAtlas;
}
- Using Unity's macros (I used these originally for the per-material texture)
TEXTURE2D(_BlockTextureAtlas);
SAMPLER(sampler_BlockTextureAtlas);
half4 color = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, ...);
- Adding it back as a property at the top
- Scaling the coordinate way up to see if normalization was disabled
tex2Dlod,tex2Dbias(the texture does have mip mapping on, so I do suspect one of these is the right choice)
yeah exactly. but i've tried playing with the depth texture by simply multiplying by large powers of two and doing modulos on them and can't see the pattern shifting as I change stencil values. which it totally should to some noticeable degree. so seems to me that regardless of what you do, the depth texture you have in the end is not identical to the internal depth buffer
but would be a lot cooler if it was! imagine all the cool stuff you could do with single pass postprocess effects with those 256 bits 😛
actually guess that makes sense, to store 24 bits of depth and 8 bits of stencil you'd have to use the exponent and sign and NaNs and Infs would map to various values, so youd have to do some interpreting to give the user usable depth
Hey people ! I was wondering if deleting Tangents data from vertices for meshes that won't be using normal maps is okay ? Seems to weight about 30% less.
Is it a good idea or could the Tangents be useful for other operations ? Does Unity get rids of tangents at runtime if it knows it won't be used?
Thank you 🙂
what is this shadder effect called, I want to make it but I don't know how
I don't know if it has a name
Looks like just a transparent texture on a cylinder, probably won't need any custom shader to make it
light shafts / god rays
thnx alot
So I'm getting this error "array index out of bounds" and I have no idea why it's giving me this. I looked through my code a few times and I don't see a moment where I'm referencing an out of bounds array. I'm fairly new to shaders so I hope someone more experienced can see what I'm missing lol.
The relevant parts of my code, a bunch of defined functions and when they're called at the bottom:
inline float linearizeSRGB(float inputChannel)
{
//data from https://www.image-engineering.de/library/technotes/958-how-to-convert-between-srgb-and-ciexyz
float output = 0;
if (inputChannel <= 0.04045)
{
output = inputChannel/12.92;
return output;
}
else
{
output = pow(((inputChannel + 0.055)/1.055), 2.4);
return output;
}
}
inline float1x3 sRGBtoCIEXYZ(fixed4 color)
{
//data from https://www.image-engineering.de/library/technotes/958-how-to-convert-between-srgb-and-ciexyz
float linearRed = linearizeSRGB(color[0]);
float linearGreen = linearizeSRGB(color[1]);
float linearBlue = linearizeSRGB(color[2]);
//good idea to check your work here
float3x3 conversionMatrix = {
0.4124564, 0.3575761, 0.1804375,
0.2126729, 0.7151522, 0.0721750,
0.0193339, 0.1191920, 0.9503041
};
float1x3 sRGBMatrix = {
linearRed,
linearGreen,
linearBlue
};
float1x3 CIEXYZ = conversionMatrix * sRGBMatrix;
return CIEXYZ;
}
inline float fXYZ(float XYZ)
{
//http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_Lab.html
if(XYZ > 0.008856)
{
float convertedXYZ = 116 * pow(XYZ, (1/3)) - 16;
return convertedXYZ;
}
else
{
float convertedXYZ = 903.3 * XYZ;
return convertedXYZ;
}
}
inline float1x3 XYZtoCIELAB(float1x3 XYZ)
{
//Matrix Values for D65: [0.9504, 1.0000, 1.0888]
//above taken from: https://www.mathworks.com/help/images/ref/xyz2lab.html
//http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_Lab.html
//float3 D65 = float3(0.9504, 1.0000, 1.0888);
float XoverXn = XYZ[0][0]/0.9504;
float YoverYn = XYZ[1][0]/1.0000;
float ZoverZn = XYZ[2][0]/1.0888;
float fX = fXYZ(XoverXn);
float fY = fXYZ(YoverYn);
float fZ = fXYZ(ZoverZn);
float L = 116*fY - 16;
float a = 500*(fX - fY);
float b = 200*(fY - fZ);
float1x3 CIELAB = {
L,
a,
b
};
return CIELAB;
}
inline float1x3 sRGBtoLab(fixed4 color)
{
float1x3 linearColor = sRGBtoCIEXYZ(color);
float1x3 CIELABColor = XYZtoCIELAB(linearColor);
return CIELABColor;
}
inline float CIE76Comparison(fixed4 originCol, fixed4 ComparisionCol)
{
float1x3 originalLAB = sRGBtoLab(originCol);
float1x3 compLAB = sRGBtoLab(ComparisionCol);
float deltaE = sqrt(
pow((compLAB[0][0] - originalLAB[0][0]), 2) +
pow((compLAB[1][0] - originalLAB[1][0]), 2) +
pow((compLAB[2][0] - originalLAB[2][0]), 2)
);
return deltaE;
}
later in fragment shader:
...
colorDistance = redMeanComparison(col, sampledColor);
I'm trying to make a simple proximity barrier to polish some invisible walls.
How can I change the alpha based on the player (or camera) proximity?
Current shader, I just need to replace that manual float (0-1) with a value based on camera distance
The ways I know of are View Vector: View to Length
and Distance of Camera: Position and Object: Position
and Remap with both the result to your liking
I'm trying this method but isnt working yet, how should I interact with the remap node?
both of these work in the range of 5 units
Object position can be changed to geometry position so it works per pixel rather than per object, and makes it identical to the View Vector method
I tried both approaches but none of them actually altered the alpha so either theyr not working (for some reason) or the actual value get changed so slightly that is not visible
I tried also to multiply x10 the result but the result is still the same
@silk sky It's best to confirm that it's working in the first place by removing other nodes and using it purely as emission, for example
I was exactly doing that
using an unused "end" like metallic or emission to check the change
So the distance works, but alpha does not?
No, i think that distance is not working, I tried to put the "preview" node in emission and the result never got altered at any distance
maybe something in the shader setting could be wrong?
I just changed the surface type to Transparent
Did you test it in the scene?
Distance can't be altered in preview nodes so it's never a good indicator
Which render pipeline are you using
I can confirm that the rest work since I was previously used a manual float instead of distance and the result was as expected
URP
Hmm I don't have any more ideas
All three ways work on my end
Not that I know of
It's tricky because the values are different for each vertex/fragment
You could try these I made to test with
Sorry for late reply, it works but I have to be very very near
I would've assumed the range is 1 unit, multiplied by 5 in the remap function which for most purposes isn't incredibly small
But you can tweak that with the remap node
yes I'll play with the values to get the result
thanks for the help tho
Updated and working version
I have just a last issue: for some reason when I select a Blue-ish color the patter disappears
I have no clue on why it happens since the preview is fine
You're multiplying the alpha by the base texture multiplied by the base color, which is just weird and I'm not sure what it does
I'll try to split
why not just
I'm not really used to the float1x3 matrix format, but maybe the array out of range is coming from those ?
You have variables of type float1x3 at different places, accessed with var[0-2][0] , maybe it should be var[0][0-2] instead ?
Why not simply use a regular float3 ?
Hi, I made a texture in Blender. In Blender the rotation of the uv islands are correct, but when I import the texture in Unity, Unity doesn't consider the rotations of the uv map.
So when I use Shader Graph to scroll over the uv map, one of the faces is scrolling the wrong way.
Do you know how to fix it?
In Blender, when I scroll down any of those islands, they go up on the model, which is the intended result
But the rotations are ignored by Unity
One of these is rotated the wrong way or flipped
Or it has multiple UV maps, perhaps
Using a temp texture that can visualize directionality might shed light on the issue
How do I do that?
which one?
Using a temp texture that can visualize directionality might shed light on the issue
That means that instead of the "uv grid" in blender you would use the "color grid"
It's not a fix per se, but it would help confirm that the UV islands are indeed in correct orientation
The color grid has numbers and letters so it's hard to confuse which way it faces
Yes, do they appear correct in the 3D viewport now?
UV editor doesn't actually tell us if the islands are flipped or rotated 180°
In blender 3D viewport, I mean
Yes
Every side?
All the As are on top all the Hs at the bottom
So how does this one look in unity
one sec
One is indeed flipped
I imported the model and the texture separately to Unity
Couldn't figure out how to import them together
After ruling out the obvious I have no idea why this would happen
How do you usually export a texture, are there specific settings?
It makes about as much sense to me as unity ignoring changes to the mesh geometry itself
I'd try to duplicate all the faces in the mesh, move them next to the pillar and UV map the new pillar wholly anew and see how they look together in unity
Unless the texture itself has flipped parts, that isn't a part of the problem
Duplicating the pillar in the mesh would also doubly verify that the mesh is indeed changing in some way
Too often I've realised that the changes didn't actually make their way to unity
Thanks for your help, I don't really understand what you mean
Would you mind checking the model and the uv map directly? I can send you the texture and the model
Sure
I don't need the texture but you could send both the blend file and unity fbx
The blend file exports and works fine
The fbx has a flipped face on the UV map and it exports and works fine after de-flipping it
I'm guessing you weren't successfully updating/replacing the mesh asset in unity
Which is what I meant when suggesting to make changes to the mesh so you can confirm that something happens
It doesn't look like much
Just select the face on the UV map and rotate it by 180°
But it looks like on the blend file you've done it already
Since none of the UV islands there are flipped
I'm guessing it was still the old mesh in your scene
Heyo I wanna learn about shaders for future things,
and currently to make the Toon/Lit have a sort of a small gradient on the edges with a color, so the edges stand out visibly
how hard would this be?
any tips?
I still have the same problem
Not sure how to do this
I implore you make some kind of change to the mesh geometry before you export it
Some change you can see in the scene to be sure it's the new mesh file instead of the old one
Toon shaders are some of the more complex types of shaders to learn, but there are many resources and tutorials about them fortunately
Now it works
Thanks, I guess I didn't export the fbx again because I thought the problem solely lied with the texture
Thanks again man, you saved me a headache
Right, that's what I meant by saying that the texture is not a part of the problem and to verify that the mesh is being imported
is it possible to apply a shader(like an outline shader) to an entire game object(say one that has multiple particle systems)?
Most of the shaders broke and opaque objects looks invisible in build. Does anybody know how to solve these?
Hey there,
Does anybody know how to do an early-z prepass in URP and HDRP shadergraph? Specifically with alpha-to-coverage so I can get nice anti-aliasing of a cut-out texture
I can see how to do it with a straight shader but in shadergraph (which I'm obliged to use), I can't see how it's done
I'm not super familiar with this specific issue but shader stripping can erroneously remove shaders from builds
Hi, I am following the unity tutorial for shadergraph, in there the tutorial connects position node to position in PBR graph. However, when I try to connect position to position in the URP lit graph, the ball preview in the main preview disappears. Is there any way to fix this? Any help is appreciated! --using view space because the tutorial is using view space
How do I reverse this model's normals so that the lighting of something inside of it doesnt look off?
I cant reverse the normals in a separate program, it has to be dynamic
How do I make a shader that looks like this, that cuts away ONLY the intersected space between two meshes?
There's an example at the bottom of the old stencil documentation page which might help : https://docs.unity3d.com/560/Documentation/Manual/SL-Stencil.html
(HolePrepare & Hole shaders)
The Unity Manual helps you learn and use the Unity engine. With the Unity engine you can create 2D and 3D games, apps and experiences.
Dude I shared the same with @tight phoenix yesterday. Idk why he’s not reading it. He should have been done by the shader by yesterday. But is stuck and asking here than reading the doc I guess
whats the attribute to show changes in editor when code is saved?
I looked at it both times, it doesnt help
again, im a fucking stupid piece of worthless shit, i dont understand any of tha,t im just a fucking worthless idiot who has to be hand fed every single fucking thing because i cannot put a fucking square peg in a square hole without
I XANT HANDLE TIHS
stop being so fucking condescending
dont fuckiung DUDE me
i get it, i get it, im a worthless piece of shit
Don’t be demotivated. You are already there. Just read the document 2-3 times
i am so deep in uncontrolable crisis
You can do it, relax an think.
I dont think i can, literally the reason i am in perpetual crisis is because i cannot do a single fucking thing on my own
Are you in the middle of a deliverable?
im not in the middle of anything im a worthless piece of shit with no friends and no job and no goals and no life, i sit in my fucking room living the exact same fucking day on loop for years at a time, i have stupid idiot dreams of making soemthing great that people will love but i cannot do a single fucking thing
how can i update shader in scene view?
because im worthless garbage who is completely untalented, and every single time i try to reach out, do anything, achieve anything, its like screaming into an endless black void
post on every single fucking social media piece of shit a hundred times a day, not a single post gets any enguagement because im invisible
i cannot handle living in this fucking society as someone who lis terally objhectively worthless garbage
if i had any value at all as a human being, people would value me, but they dont, because I dont
WTF?
i am on medication, it does fucking nothing
i see therapists, they take my money and tell me to fuck off after an hour
Dude you are already writing shaders that hardly anyone can do. Just relax and calm down
yea shaders are pretty hard. I wrote multiplayer game lobby and rooms from scratch. it was a bit easier, tho some iof it was harder
telling people to relax and be calm works LITERALLY NEVER fyi
This what you did right?
shaders have hard terminology to wrap head around b4 getting good at it
What do you mean? They just render the object in any view
i plugged a normal vector node into an inverse node into the vertex fragment part of shadergraph
when i save the script, I have to press play to see the shader effect updating/taking place in game view. I'd rather that it updates in scene
trying to help me is pointless, i am in mental health crisis
i can clear as fucking day say that, but it in no way allows me to exit being in crisis
just take a break, a nap, drink some water or juice
If it’s done via script as in c#, just write [executealways] right above the class
AW GEE YEAH WHY DIDNT I THINK OF THAT JUST TAKE A FUCKING BREAK
whn does this hypothetical 'break' end exactly
ive been 'on break' since being fired from my last job for about 5 years now
how much LONGER do I have to be on break before my fucking life is allowed to start again?
I get brain fog if i go coding more than 10 mins. so i need to take a break or I just sit there without being able to finish what im doing
when do i get to feel feelings that are positive again? when do i get to wake up before 2pm? when do i get to have friends, a life, joy, when do i get to be able to control how i feel ?
i cannot handle being alive
so yea, take a break, come back when you feel a bit more refreshed.
Make simple shaders that you can understand… everyone starts small… one step at a time, go slow
i dont have a single fucking person or family to rely on, i know this is the shader forum of the unity discord, do you think i have a single other place i could turn if I am posting this here
What you’re trying to do is making a tough shader. Relax and try smaller easier things. That would build your confidence
just posting here for everyone that this needs to be checked to update materials
hey man, eating, sleeping and exercising are the most important things. Focus on them. A walk outside everyday always helps. Finding a hobby is always a way to meet other people. Volunteering is one the best ways actually to meet and help other people. Joy comes from giving, not from getting.
Thank you for the kind words and suggestions. I am struggling a lot today but thats not an excuse for my behaviour
Hey guys, if my compute shader works on both dx11 and dx12 is there any reason why it wouldnt on vulkan?
Heya ! Sorry for the sudden ping but I had a question about normal maps and triplanar mapping.
You helped me a lot last time and your node library is perfect, however I tried making normal maps and I can't seem to find how to make normal maps work with it
Yeah I think I’ll just change all the matrices to float3s and manually do the matrix multiplication and see what happens
Thanks for taking a look, appreciate it :)
do you have any tutorials on how to read/write data to a shader, specifically binary data that will change how the effect looks
I googled and can find no tutorials, resources, or anything
use case example: 3d volumetric fog of war, like a voxel grid of fog, recording where is revealed vs not
and then applying shader to the surfaces in the areas that are not revealed
Hello, I have a problem with the textures of the particles, the textures are purple
dont crosspost
sorry
i think you can use layers
With a culling mask?
The dynamic real-time spotlight has a layer, and I unchecked that layer on the main camera, yet I still see it
oh
If I can't use a culling mask to remove a light from the POV of one camera, could I brighten up the view of the camera in which I want to see in the dark?
Like via post-processing or something
Hey,
Im working on a horror game where its completely dark (appart from lights here and there for important player progression I have a toon shadder (https://www.youtube.com/watch?v=whmPkDp3dqo) that works but doesnt make it completely dark at the end. Ive tried things here and there and the closest ive gotten was to make it basicly only have 2 colours. (idk how to explain it too well without images sorry). idk shader graphs that well so any help would be appreciated.
✔️ Works in 2020.1 ➕ 2020.2 ➕ 2020.3 🩹 Fixes for 2020.2 and .3:
► When you create a shader graph, set the material setting to "Unlit"
► The gear menu on Custom Function nodes is now in the graph inspector
► Editing properties must be done in the graph inspector instead of the blackboard
► In Lighting.hlsl, change the line "if SHADERGRAPH_PREVIEW...
what i have
closest ive gotten
any math that can be moved from fragment shader to the vertex shader should be done so. Can I have an example on what type of data should be moved from fragment to vertex?
Guys, there is a question. Unfortunately, I'm not good at English, and I can't find information in my native language.
Matrices M/V/P, MV/VP/... and so on - what space are they in?View, World, Local, Clip?
As I understand it, then
unity_ObjectToWorld - Model space to world space transform.
unity_WorldToObject - Inverse of unity_ObjectToWorld.
UNITY_MATRIX_V - World space to view space transform.
UNITY_MATRIX_P - View space to clip space transform.
UNITY_MATRIX_MV - Model space to view space transform.
Vertex data - world space
Does anyone know or have reference/documentation on how to do Gouraud shading in unity as apposed to phong, im WAYYY out of my field in this and I really cant find anything on it.
iirc, gouraud is calculating lighting in the vertex stage then interpolate it in the fragment shader
I'm using a Surface Shader with Standard Lighting model for a projector material in the builtin render pipeline, sadly, this results in an unpleasant shadow being cast, here seen in black.
Any ideas on how to bypass this, are there any tags or pragma statements I can use?
"ForceNoShadowCasting"="True" - doesn't work
I also checked the enabled keywords on the surface material that weren't added by me, and I disabled all of them in code, the shadow was still cast.
Does anyone have experience with how to circumvent this issue? Or what other lighting model or configurations I could try?
Here is how it looks, ideally there should be no black parts
Or has anyone gotten a surface shader to work on a projector material without it casting such shadows? (or seems like it might be a fragment in the projection itself)
They are "just" matrix data. They convert to a space. So objectToWorld converts from object-space to world-space. WordToObject is the other way around. Etc.
Vertex data comes into the vertex stage in object space. It gets converted to clip-space by the vertex stage. Could be converted to any other space in addition, and stored in the v2f data, as the programmer wants/needs.
The spaces can get confusing.
the descriptions you posted for the matrices tell the spaces they convert from and to already,
when you are in the vertex pass, you will usually get the information in object/local space
from the incoming appdata input
So, I understand correctly that all shader input vertexes are stored in Clip space and I need to transform them exclusively in the following order: Clip -> [Projection Matrix] -> Eye coordinates -> [Viewing Matrix] -> World coordinates -> [Model Coordinates] -> Object coordinates?
But when in pass, are they already transformed?
When I work with vertex pass, do I work with local vertexes?
Input data, like vertices or normals in the builtin pipeline (I guess it should be the same for newer ones) would be default come in object space/local space into your vertex method, then they are usually transformed into clip space and passed to the fragment pass
I meant it that way)
so in a vertex pass, you already work with local vertices by default. There is an instance where it is annoying though, baked skinned meshes (like if you bake them into a separate mesh), because by default it will take the position and rotation of the skinnedmesh renderer as origin, but will not include the scale the skinnedMeshRenderer transform
oh sorry, I misunderstood. then yes
Then in reverse order
Last question. As I understand it, to get the camera matrix, reverse view matrix is enough, isn't it?
I've just been sitting here all night (I've never written shaders, I haven't worked with matrices). It would be possible to find it on the Internet, but I have a mess in my head by morning) But, in general, I am already close to the truth and, one might say, figured it out) Thank you very much)
I found this article,
with camera matrix do you mean the view space?
https://learnopengl.com/Getting-started/Coordinate-Systems
yeah)
I don't really handle matrixes well either, but as far as I understand it, if you have a matrix that transforms from one to another space,
you can transform the other way around by inversing it,
I think that happens by multiplying a matrix by 1 / it's determinant
Maybe we should ask - what do you want to do or what feature do you wanna write with that knowledge?
No, just experiments with matrices) I want to learn to understand them a little better) With my own head)
Actually I have already received enough information to continue + especially your article is very useful! so compact, everything is needed without bloating
*And Unity has all the necessary tools to quickly visually see the results)
I don't really look up mathematical things, but this site has articles that make it easy for me to understand certain concepts too
https://www.mathsisfun.com/algebra/matrix-introduction.html
[Disclaimer: I am terrible with shaders]
Hey, I've been struggling to make a toon shader. First I tried making the lighting through shader graph in URP with a simple (I think it's called) Lamber model and a custom subgraph (which I stole from a user in this channel) for recieving shadows but they looked awful, I am now trying to code a standard surface shader in the built-in renderer but now that I look at the shadows in built-in, they look even worst.
So, should I try and improve the shadows in built-in/URP? Or should I try on HDRP with coded/graph shaders?
Take a note. To make the shader fit well, edit the normals. The blender has Data Transfer and Normal Edit for these purposes. And the lessons can be found on the Internet.
the concepts are the same,
surface shaders are usually not well suitable if you want toon shading because they have more realistic, sometimes physically based lighting models by default,
but if you implement your own lighting function, or use a vertex fragment shader, or if you use a shadergraph:
basically you could get the dot product between the normal direction of each pixel of the model and the view direction of the camera. you'll get a value between -1 and 1. Based on this value you can decide on a shadow color you multiply the original color with.
no shadow would be a shadow color of white (1,1,1,1) - so that the input color stays the same.
I don't have a specific tutorial for you, but if you look up more about toon shading/cell shading, I'm sure you'll find plenty of tutorials
Ned Makes Games has pretty good tutorials, although I haven't watched this one:
https://www.youtube.com/watch?v=RC91uxRTId8
However, I watched this, and it was super interesting. If you have the basics of shadergraph down, you might be able to implement something like this
https://www.youtube.com/watch?v=mnxs6CR6Zrk
✔️ Works in 2020.1 ➕ 2020.2 ➕ 2020.3 🩹 For 2020.2 and .3:
► When you create a shader graph, set the material setting to "Unlit"
► The gear menu on Custom Function nodes is now in the graph inspector
► Editing properties must be done in the graph inspector instead of the blackboard
► In Lighting.hlsl, change the line "if SHADERGRAPH_PREVIEW" to "...
Let's figure out how The Legend of Zelda: The Wind Waker was able to pull off cel shading at a time when nobody else was able to.
🐦 https://twitter.com/JasperRLZ
💰 https://patreon.com/JasperRLZ
🤼 https://discord.gg/bkJmKKv
🌎 https://noclip.website
🎵 Jasper - Epoch ( https://www.youtube.com/watch?v=DDmzbYV0d9M )
🎵 Allister Brimble - Fluidity - ...
I trust blender's recalculated normals, although, now that you say it, idk if unity imported those normals or remade their own
That's what I did for the model's shadow, the problem is the shadows the model recieves
and like Rocco says, it's important to have the normals of your model setup correctly,
usually, artists who purposefully make their models for toon shading play with topology and custom normals so that the model looks well from each lighting direction
ah, maybe it would be easier to not use a surface shader and start with a vertex fragment shader (there is less magic going on), or if you disabled receiving shadows
I did follow the Ned Makes Games one, but not the other one. Thanks, I'll watch it straight away
on the renderer, should be possible in the shader too but nto sure how
Problem is, I do want recieving shadows xD
I've tried to get them working in 3 different ways now
oh 😅
I never did those calculations manually,
am currently having shadow issues with my shader too, it's not casting them anymore, but it also doesn't receive any
Not using built in surface alpha/decal blend instructions (like alpha:auto) and instead put the command "Blend SrcAlpha OneMinusSrcAlpha" separately seems to solve it,
but I'd like to have the regular alpha blend behaviour in surface shaders, just without this shadow
Could you please describe what you did ?
Maybe something you missed, is that I didn't implement a "normal mode" for triplanar sampling the normal texture.
You'll have to sample the texture, and the pass the result into the "normal unpack" node
i have a graphic which i want to combine a color and a background color - i have the two bits set up (make the texture green, the background red), but i dont know how to combine them into one graphic. this was my best attempt.
i think Add is being weird, right? adding (0,0,0,0) to (0,1,0,0) would equal green for the green pixels ... right? help would be appreciated ^^
Yes, but there may be negative values if you are subtracting values higher than 1, and so the black isn't necessarily (0,0,0,0)
Can use a Saturate node to clamp between 0 and 1
ooh that might be the solution! I'll try that thanks ^^
Let me boot up the project and I'll show you how I tried it
Hey people!! are there any good resources about translating custom builtin RP shaders (Cg) to URP (HLSL). Unfortunately I am more experienced with GLSL and never really wrote much Cg or HLSL. It seems like it might be an easy task but I am a bit stuck in a rabbit hole of one error solving after the other with no real end in sight.
I am trying to convert this awesome tool to URP: https://github.com/RoyTheunissen/GPU-Spline-Deformation/blob/master/Shaders/Deformation Lookup Shader.shader
The easiest way to handle this would be with a Lerp node (equivalent to a(1-t) + bt). The Blend node with Overwrite mode is also the same.
If you have a float (black/white preview) of the shape, put that into the T input on the Lerp, then set A and B to the colour properties.
that did the trick! ty!
Here is what I tried
The top part is for the texture
Yep, you'd want to use the normal unpack + normal strength node instead of the multiply
isn't the vertex position that is passed to the vertex shader supposed to be in model space ?
col.rgb = normalize(i.vertex) * 0.5f + 0.5f;
this should give me the same color despite where the camera is
but it acts like its view space
Thanks !
nvm it was my mistake
what was it? did you use UnityObjectToClipPos in the vertex function ig? also note that interpolator with SV_POSITION semantic will not be the same in fragment shader as you set it in vertex shader (I think unity transfers it automatically from clip space to pixel coordinates or something like that)
Hey! So that’s a surface shader that’s why it’s confusing. Here’s what you can do:
Take a sample hlsl code from unity’s online documentation site.
Copy n modify the vertex shader code and use it in the vertex function.
Consider the code in surface function as the fragment shader code
@normal solar that’s your sample for hlsl: https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@8.2/manual/writing-shaders-urp-basic-unlit-structure.html
That's what I did (or at least tried to do...)
I'll check the example, thanks a lot @quaint coyote
I will try again
From what I could make out from the link you shared, modifications are done only in vertex shader. So nothing in the fragment shader.
What errors are you getting?
🙂 THat's the problem, I either get no errors and a flat white shader or an error complaining about fixed4 not existing (the code does not include fixed4, I switched it all to float4)
But I see from the example code you are sending many things I could try.
Really tough to say anything 🤓
I am pretty sure I was making a mess with the arguments/return values of the vert and frag functions
Hmm, might be. Good luck though 👍
If you get any errors drop them in here. If there’s anything I could understand from them, I’d help you out. 👍
Super cool @quaint coyote thanks so much!! I had to skip to the next task cause I am running a bit late but I will get back to it soon and post stuff here. If I manage to convert it properly I will commit it to a fork of the repo and make a PR then you guys can also use it if you need.
Sure 👍
Does anyone have any idea how I would go about widening a texture gradually?
The obvious parameter to tweak is Tiling, but that does not increase the size based on a center point. It extends the texture starting from a corner point.
my math kung fu is weak I know
((uv - 0.5) * multiplier) + 0.5 maybe?
Not sure if this is the right place to ask this, but I am getting a weird issue when Unity compiles my shader. Specifically this function:
float GetHue(float2 pos, float angle) { float rads = radians(angle); // this line seems to be the issue, it complains about swizzle. return pos.x * cos(rads) - pos.y * sin(rads); // If I instead do this I get no compilation error: // return 1.0f; }
Unity gives me this error when it compiles the shader:
GLSL compilation failed: 0(46) : error C1031: swizzle mask element not present in operand "z"
when calling this function I am just passing in i.uv and a material defined float angle from the standard frag function
Replace rads with 0.0 once and try?
that seems to fix it. Am i calling the radians function incorrectly?
after testing more the issue seems to be with using my angle variable. If I change it to:
float rads = radians(0) or float rads = 0.0 * PI / 180.0
it compiles fine, but if I use
float rads = radians(angle) or float rads = angle * PI / 180.0
I get the error
Its likely to do with how you calculate that angle variable
aha i found the issue, it was weirdly that I had previously setup my _speed variable (another float) as a float2. I am unsure why that was affecting the use of the angle variable, but now that I have made that change, it doesn't complain about using angle anymore
thank you!
Anyone know how to go about fading only the beginning or end of a line renderer material ?
The harsh ends looks so bad and amateurish
but I'm using a shadergraph for my material, so I cannot make use of soft particles feature 😦
The line renderer material has a color gradient, have you tried just using that?
I have! That simply does nothing. Even when I add an excess of points to the line, the color and alpha of the gradient just get ignored entirely
That's with ??YOUR graph??, but have you tried it with a standard particle material?
standard particle material does use the gradient. But I do need my own shadergraph because I'm doing bullet trails and I need two textures scrolling along the x direction at different speeds for the effect 😦
Is there some setting I can add to the shadergraph to make it consider the gradient settings of the line renderer ?
IDK off the top of my head, but you can try vertex colors. IIRC particles (and maybe line renderers) use vert colors.
So maybe the line renderer is setting the vert colors on the line's vert points.
oh yeah I'll look into that!
Otherwise I'd have to research, which you can do too now. See how the particle shaders work for your rendering pipeline. There's also code repositories for them, depending on pipeline.
I'm new to shaders, so forgive the newbie question lol. But as I understand it, when the shader compiles, it checks to see how many iterations a for loop will go through before running the code, right? That's called unrolling if I'm not mistaken.
So, I have a for loop that runs for every pixel in the width of a texture. Assembled like this in the fragment shader:
{
...
}```
So, this doesn't need to be unrolled.. because of reasons I don't understand.
However, when I put this same loop in an if statement:
if (condition)
{
for (int j = 1; j < _Palette_TexelSize.z; j++)
{
...
}
}
Suddenly it returns this warning:
`gradient instruction used in a loop with varying iteration, attempting to unroll the loop at line 347`
and this error:
`unable to unroll loop, loop does not appear to terminate in a timely manner (607 iterations) or unrolled loop is too large, use the [unroll(n)] attribute to force an exact higher number at line 342`
Why does it have issues with the same for loop in an if statement, but not otherwise? How would I fix it?
This doesn't look like a case where the loop can be unrolled anyway. _Palette_TexelSize.z doesn't look like like a constant number. It will be different based on the size of the _Palette texture. The compiler can't know what textures will be used.
Right, that I understand, but then why only return the error in the if statement?
the loop works fine normally
but when I run it again, (it runs once normally, then again based on a condition defined in the if statement) it gives the error ONLY then
It's because you're using a "gradient instruction" inside an unrollable loop. A gradient instruction is something like tex2D.