#archived-shaders
1 messages · Page 54 of 1
because the edges are not all uniformly the same value, they're all over the place, its only the centers the same value, so I am not able to mask the edges
but like, this person 100% is getting the edges
but I can't seem to parse their code
The "Out" preview on the NewVoronoi node looks like distance to edges, but also looks like regular voronoi not the Chebyshev one
im using a blend node in overwrite mode to overlay an image with transparency (overlayImg) onto another texture. How can I make it so that this step doesnt happen if overlayImg is empty? At the moment, if it's empty, the overwrite turns the output fully white.
Would this be a branch node or something?
https://paste.ofcode.org/kEQJVC68wXkX5hKW5iMVYV this is the code of the most recent attempt, I've started over from scratch every time I hit a wall I can't solve on my own so I am so neck deep in variations I no longer can see what any of them do
This only makes this harder, my comprehension sucks no matter how many hours I put into it, it feels like nothing ever becomes clear
I assume you're using the alpha channel of the texture as the blend amount? If you change the Texture2D property to "Black" under the Node Settings (rather than White) it should default to 0 alpha.
I was! Thank you that worked
I have a feeling these sort of calculations might be assuming an Euclidean distance still so might be why it doesn't give the correct output.
float d = dot(0.5 * (mv + v), normalize(v - mv));
res.x = min(res.x, d);
I'll play around a bit and see if I can figure it out
currently googling more shadertoys looking for one that has less superflous features in it, its always so hard to parse what is doing the thing I want from the mash of extra visual flair stuff
Alright, Ill keep poking on my end as well. There are some distance functions for various distance spaces at the top of the code if those help / are useful / are even correct
Chebyshev Voronoi Edges
my scene looks dramatically different in build compared to game view of the editor
how can I debug whats occuring here?
I cant click on and inspect any of the assets in the build version, and those are the ones I need info about
I have the debug profiler hooked
but how do I find that sepcific thing?
I found the specific thing 🤔 through manual experimentation with what I figured it might be
Not sure how to fix it yet though
the problem is that I'm running this: ``` matPropBlock.SetFloat("_GlobalBrightness", value);
that value is getting set to 0 in build but not in editor
I dont know how that is possible because nothing in the scene is even scripted to do that
and its default value is 1
do MaterialPropertyBlock work differently between editor and build?
ah, found the deeper actual problem
I am writing barycentric coordinate data to triangles, but the method that does this can't run at build runtime
the shader needs that data to be visible, thus why it was vanishing
Can someone help me understand why this code isn't getting me a fragment's OS position?
// clipspace frag position
float u = IN.vertex.x * 2.0 / _ScreenParams.x - 1.0;
float v = IN.vertex.y * 2.0 / _ScreenParams.y - 1.0;
float4 ro = float4(u, v, -1, 1);
// obj space frag position
ro = mul(UNITY_MATRIX_IT_MV, mul(unity_CameraInvProjection, ro));
Object space position is just what you get in vertex shader in parameter with SV_Position (or POSITION) semantic. Your code trying to (incorrectly) make object space position of pixel that reside behind camera at imaginary far plane.
SV_Position is screen position right? e.g. in 1920x1080 space yeah?
No. I'll give you an example
"... the SV_Position semantic (when used in the context of a pixel shader) specifies screen space coordinates (offset by 0.5)"
struct v2p
{
float4 pos: POSITION;
float3 objectSpacePos: TEXCOORD0;
};
v2p vs(float3 vertex: POSITION)
{
v2p o;
o.pos = UnityObjectToClipPos(vertex);
o.objectSpacePos = vertex;
}
float4 ps(v2p i): COLOR0
{
// i.objectSpacePos is your object space position in pixel shader
return float4(i.objectSpacePos, 1);
}
Something like that
This is correct
ah ok
So the space we're in in the fragment shader is clipspace
I'm not sure how unity handles the nearplane, I've tried both 0 and -1 which afaik are the standard options
Hi, I just imported an asset I got from the asset store and the materials are all pink. I had a look and they're using custom shaders. I'm also getting this issue:
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)```
Unity version 2021.2.8f1, and using URP
I'm trying to get the position of of the fragment in object space for the origin of a raymarching ray. I have the position of the object in object space (the hit of the ray) no problem
Why is the UV Coordinate node in Shader Graph a Vec4? What do the ZW channels represent?
I thought UV Coords are just Vec2?
I noticed that some packages show which rendering pipelines are supported. But it is not shown in the web page for my asset. How can I fix this?
Hey everyone. I have a standard set of shader VFX I need to apply to all my models (like glow, fresnel, changing its albedo color). Every model will have the same pack of effects. I remember that it's generally not recommended to put multiple materials into a single mesh. Also, our game will have mods and that probably will include adding user VFX. How do I do this right? Do I have to combine both my surface shader and VFX into a single material or can I split them into multiple separate materials? What are drawbacks? (I'm using HDRP)
this seems more like an asset render pipeline compatibility question than a shader question. either contact the publisher of the asset for support (if they support URP,) or find another asset that is compatible with URP.
not really a shader topic, this is an asset publisher portal question. i suggest to try another channel like #💻┃unity-talk , the forums, the docs, or contact unity asset publisher support.
the zw components could be used for a second set of uv coordinates, tiling and offset for texture atlases, sampling cube maps or 3d textures or a completely novel technique that no one has ever thought of. anything really ¯_(ツ)_/¯
it sounds like you may want to look into HDRP custom passes https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@16.0/manual/Custom-Pass.html
fortunately, there's a number of raymarching tutorials and examples out there for unity. i recommend to follow one of these or at least examine their code as a frame of reference https://youtube.com/playlist?list=PL3POsQzaCw53iK_EhOYR39h1J9Lvg-m-g
https://youtu.be/S8AWd66hoCo
In this video we'll code a ray marcher inside of a shader in Unity that allows you to render 3d objects on the surface of other 3d objects, like a hologram!
Twitter: @The_ArtOfCode
Facebook: https://www.facebook.com/groups/theartofcode/
Patreon: https://www.patreon.com/TheArtOfCode
ShaderToy: https://www.shadertoy.com/user/BigWIngs
PayPal Dona...
I got it figured out
transposing the matrix multiplication to go from camera space to object space ended up fixing the issue
float4 ro = float4(u, v, -1, 1);
float4 camSpace = mul(unity_CameraInvProjection, ro);
// obj space frag position;
ro = mul(camSpace, UNITY_MATRIX_IT_MV);
Is there a way I can make a camera render red and green in a normal way, but get only the minimum of the blue channel?
Like from all the colors that are affecting a certain pixel, get the minimum of all
Ah ok, thanks!
I think you would need custom shaders and/or postprocessing for this
if all your objects use a shader that takes the scene color and mins it with its own blue channel for example
Alpha blending cannot be configured per-channel. So you will need multipass approach. Set BlendOp to “Min”, Blend to “One One”, and ColorMask to “B”. Then render all interested meshes. At the end you will get minimum in blue channel.
For “RG” channels you will need separate pass. You can use alpha channel as imaginary “B” channel. Alpha channel blending can be configured separately from RBG
This approach can be easily done with RWTexture2D usage.
Where would I do this? In like a material shader used for blip onRender? Or on the material of the object which this rule applies?
If its not too much, could you write somd pseudo code for how it would look like?
I think i understand the B channel thing, but not the RG
Got an issue with shadow attifacting with custom spot light shadows.
If someone can help it is greatly appreciated:
https://forum.unity.com/threads/artifacts-at-the-edges-of-spot-lights.1463939/
It's for a particle, but I cannot get it to work, by just using the unlit shader im already getting Z culling errors
Alpha blending is configured per-material
Okay, so for example, how can I get the Youngest in front sort mode of particles to work on a custom shader¿
For RG channels you should use ordinary shader just with ColorMask RG.
What kind of Z culling errors do you have?
Sorry, I don’t understand your question. Can you clarify please?
Yes, so on my particle System, I have this enum set that makes it that the youngest is always rendered on top.
Now, what I understand is that, i need to create a custom shader that will have first a pass that blends and gets the minimum of blue, then a second pass that renders Red and green and somehow get the blue from previous pass, (not super sure how) and then defined the remaining fields that would be needed to keep that particle working too
This is as far as I got
So, you need two-pass shader. First pass will calculate minimum in R channel. Options for this pass: “ColorMask B”, “BlendOp Min”, “Blend One One”
Second pass will have just one additional property: “ColorMask RG”
Okay, so something like this
Ah! Disabling the Zwrite fixes that problem i had with the sorting!
Not sure how to remove the yellowish thing
Aha! changing it so that the first pass only returns the blue channel removes the yellow
Ah, not that's what I thought, but not really removing it
that's because blue also needs to be transparent with alpha
is that possible?
So transparent or minimum? You can premultiply color with alpha in shader
I need the minimum of all blue channels, but it's creating blue values where they don't exist (where it's transparent)
I am not sure that it what you need, but alpha premultiply can help you: outColor.b *= outColor.a;
Ah, multiplying wasn't working because where the texture was transparent i was getting a value of zero on the blue channel, where I actually needed a 1 there, the solution was
return float4(0,0,col.b+(1-col.a),0);
Now the result of all particles becomes this texture, which is what I wanted
Maybe the scaling is different, it should be identical if world space and object space are the same (i.e. no rotation, no scaling, no offset)
Some objects have rotation, I am trying to make it work with those because they float around
Idk how to, I’ve been stuck for a little bit
hey y'all, i'm having a little problem with some assets i downloaded. I'm working in Unity 5.6 because i'm modding a game but i tried importing assets made for unity 2020 after using the built in converter to make them usable with legacy shaders. However, something about the shaders or the code isn't working and is producing this conondrum. Please let me know if you have any suggestions.
made a shader graph called "scanned"
tried to make a mateiral from it but its just blank on the right side
tthere are no options for me to change anything like i have made the variables in the actually shader you can see on the left
the base color and fresnel power.
but i have no options for those in the inspector after creating a material from the shader graph
nvm i fixed it
didnt save asset
hm, but still have some problems. the shader isn't working as intended
the main preview is completely blank, and even after chaning settings in the material i create from the shader, nothing changes
nvm fixed
Hello, is there a way to set the normal of a pixel being rendered in a surface shader? I want all pixels to be rendered with the same normal (therefore being lit the same way) regardless of the mesh. I also need shadows so I can't use an unlit material.
I did try setting the normal of the SurfaceOutputStandard, but that doesn't seem to work. Half of the mesh is rendered (kind of) normally while some faces are all black.
Could you try also setting htese to 0?
half Smoothness; // 0=rough, 1=smooth```
I already do. Setting those to zero just gives diffuse lighting. I want the whole mesh to be lit the same even if the face is opposite the light source.
It would basically be like an unlit material that casts and receives shadows
right I wasn't sure if you were already, because I think diffuse lighting would be required for that effect
but with faces that are not facing the light can't he object itself be casting a shadow on itself?
Yeah, that's why I want to set the normal of every pixel or fragment or whatever to straight up so that it uses diffuse lighting but is completely lit
In reality, yes. In what I want to do, no.
Do objects cast shadows on themselves in Unity?
Is there a way to disable that?
Nvm, I found a shader online.
the concept is sound. I've seen it done before
maybe just an issue with your implementation
Found this article https://danielilett.com/2021-11-06-tut5-19-glitter/ problem is now fixed
Yeah if you use everything in world space it doesn't care about rotation vs if you use object space, it does. Only difference might be the actual numerical factor you put in for the world bending effect
MaterialPropertyBlock did not contain SetInt at that time. You need to replace ints with floats in your shader, and SetInt calls with SetFloat.
Shader "Example/TestShader"
{
SubShader {
Tags { "RenderType" = "Opaque" }
CGPROGRAM
#pragma surface surf Lambert
struct Input {
float4 color : COLOR;
};
void surf (Input IN, inout SurfaceOutput o) {
o.Albedo = 1;
}
ENDCG
}
Fallback "Diffuse"
}
why is it pink... I pulled this straight from unity
Figured it out, it needed a default Cull front
Nvm, it doest work
Shader "Example/TestShader"
{
SubShader {
Tags { "RenderType" = "Opaque" }
CGPROGRAM
Cull Front // this line is suppose to be before CGPROGRAM
#pragma surface surf Lambert
struct Input {
float4 color : COLOR;
};
void surf (Input IN, inout SurfaceOutput o) {
o.Albedo = 1;
}
ENDCG
}
Fallback "Diffuse"
}
when I do this, the sprite works
although the code is wrong
{
SubShader {
Tags { "RenderType" = "Opaque" }
Cull Front // this line is suppose to be before CGPROGRAM
CGPROGRAM
#pragma surface surf Lambert
struct Input {
float4 color : COLOR;
};
void surf (Input IN, inout SurfaceOutput o) {
o.Albedo = 1;
}
ENDCG
}
Fallback "Diffuse"
}
If i do this, the shader is back to purple
I have tested this with both Cull Front/Back/Off
what is GOING ON!!
What render pipeline are you using? Surface shaders are only supported in Built-in, not URP/HDRP.
O
Im in URP
Then yeah, not supported. That's why it's magenta. It's usually recommened to use Shader Graph instead
I figured shader graph would be limiting in the long run...is that the case?
Hmm perhaps? There are some things shader graph can't do. Depends what you need the shader to do.
Can generate code from a graph (though that tends to be pretty unreadable). Could also copy one of the shaders under the URP package as a basis then edit if you really want a code one.
But it is easier with a graph and less likely for the shader to break with updates to the pipeline.
I see
Why is it taking so long, I don't have a shader that I created myself, I use it from the assets that everyone uses and not much
is ur code running?
is it paused at a break point?
post shader
you can click on material and click edit to see shader code
Thanks!
I don't have shader code, I don't know if it's because of URP's own codes, I haven't dealt with shaders in the project
the assets themselves should have shader code
click it and send us code
There are 20 shaders in the project. I don't know which one is wrong and it doesn't show. If it gives an error after the build is finished, I will post it here
hmm
there is no point waiting
just restart, if it didnt work in 3 hours sure as hell wont work in 6
even if it does take 6 hours to work
its no sensible because everytime you make changes are you really gonna wait 6 hours?
ok how do i find it now
find what?
why is it taking so long regarding shaders?
error
public static void BlitTexture(CommandBuffer cmd, RTHandle source, Vector4 scaleBias, Material material, int pass)
{
s_PropertyBlock.SetVector(BlitShaderIDs._BlitScaleBias, scaleBias);
s_PropertyBlock.SetTexture(BlitShaderIDs._BlitTexture, source);
DrawTriangle(cmd, material, pass);
}
this is the error code
s_PropertyBlock.SetTexture(BlitShaderIDs._BlitTexture, source);
So what am I supposed to do then? I’ve pretty much tried everything
any1 know why my materials arent matching?
struct appdata {
float4 vertex : POSITION;
float4 color : COLOR; // Assuming the colors are provided as float4 in the C# script
float2 uv : TEXCOORD0;
};
struct v2f {
float4 pos : SV_POSITION;
float4 color : COLOR;
float2 uv : TEXCOORD0;
};
v2f vert(appdata v) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.color = v.color;
o.uv = v.uv;
return o;
}
// Fragment shader
// This shader simply passes through the color to the output
fixed4 frag(v2f i) : SV_Target {
fixed4 col = tex2D(_MainTex, i.uv);
// col *= _Color;
return col;
}
I think if you have something that roughly does
worldPos = worldPos - vec3(0,1,0)*(worldPos.x * worldPos.x / x_radius + worldPos.z * worldPos.z / z_radius)
where worldPos is the world-space vertex position, then it should create the desired effect. (If the object has triangles about as large or larger than min(x_radius, z_radius), you will have issues). There should not be any dependence on rotation or scaling with this. (You can switch the Vertex node to take a world-space position so you don't need to do any transformations yourself)
I may have a script for something like this, I’ll try it
Are you sure the UVs on the mesh are set up correctly?
Not sure, still learning 🙂
how can I verify
If you do col = fixed4(uv, 0, 0); it should show the UVs and it should be black in one corner, yellow in the opposite corner, and then green and red in the two remaining corners
Im guessing this si bad
Strangely enough the original mesh is fine
I am creating a procedural mesh
yes so you're just sampling one corner of the texture across the whole mesh, which is why it's just solid color
I believe there's a mesh.uv array which you can set
what do I set it too?
if you don't want the texture stretched and it's aligned perpendicular to z, we can define d = max((max(vertices.x) - min(vertices.x)), (max(vertices.y) - min(vertices.y))) as the size of your mesh, and then you want your uvs to be Vector2((vertex.x - min(vertices.x))/d, (vertex.y - min(vertices.y))/d) where vertex is the particular vertex for that element in the array. (note that max(vertices.y) is not valid, if you don't a priori know the maximum size of your mesh, you will have to loop over the array. You probably do know how big the mesh is though since you're making it with code so it should be fine)
What is the best way to add depth to my meshes
Using different materials has its limits
How can I use Nsight's shader profiler with Unity?
I can't seem to get a build to include shader symbols
Wait actually how do I make a script for this or add the right nodes in the shader?
Shader error in 'Universal Render Pipeline/Lit': maximum ps_4_0 sampler register index (16) exceeded at INVALID_UTF8_STRING(9) (on d3d11)
I am getting this error after getting build
I made a shader graph that curves world but objects that have rotation have this weird offset and float around. I still haven't been able to fix this after a few days
Hey, is there any possible way to use a graphics shader with a compute shader? I'm trying to use the Raymarching technique to blend meshes together to simulate a fluid like effect, I'm using URP
Does anyone know of a great source for making unity shaders? I want to create 2d effects on a cimple circled. is something like this possible in unity ? https://www.youtube.com/watch?v=f4s1h2YETNY
In this tutorial, I explore the fascinating realm of shader art coding and aim to offer helpful insights and guidance to assist you in beginning your own creative journey. I hope to share my passion with you along the way!
Final shader: https://www.shadertoy.com/view/mtyGWy
Resources presented in the video:
• Shadertoy: https://www.shadertoy.c...
like can this be applied to a basic white circle sprite?
@karmic hatch do you know of any good sources for this ^^^
there's a few video tutorials for converting shadertoy shaders to unity built in render pipeline / shaderlab: https://www.youtube.com/results?search_query=convert+shadertoy+to+unity
you can also look up general GLSL to HLSL resources like this which are also helpful. the languages are very similar in structure. https://learn.microsoft.com/en-us/windows/uwp/gaming/glsl-to-hlsl-reference
or if you are using Universal RP or High Def RP, there are some converters on the asset store from this developer that would give you a head start. also for Shaderlab / Built in RP looks like https://assetstore.unity.com/publishers/72922
yes, you can execute compute shaders that write to a graphicsbuffer or computebuffer or texture, and then read those buffers or textures in traditional "graphics" shaders i.e. vertex or pixel shaders. all told this can be quite an endeavor but there are some examples out there. here is one with links in the video's description to example code and also some assets that are further developed and more efficient https://www.youtube.com/watch?v=eisCx-pC0oo
Using modified version of https://github.com/hecomi/uRaymarchingExamples by @hecomi
*This is way too heavy for anything useful, try these assets instead:
https://assetstore.unity.com/packages/tools/particles-effects/mudbun-volumetric-vfx-modeling-177891?aid=1101lGti or https://assetstore.unity.com/packages/tools/game-toolkits/clayxels-165312?aid...
thx
np. there's also screenspace fluid rendering, and isosurface mesh generation like marching cubes, dual contouring, or surface nets. just to give you some other techniques to look into.
Why is my sprite showing up as this color? what
the green should be transparent and the yellow should be white
what does the source texture look like in the inspector? (not in shadergraph, before that)
it looks how i described
can you screenshot that, and the texture format listed below the inspector preview
there's weird texture formats sometimes
even the built in sprites?
I've now followed two separate tutorials for some water shaders and both times after applying the shader to an object my unity editor Scene tab is very choppy.
The game runs fine and if I RMB and move around in the Scene it runs smooth.
Is this a normal issue?
wild, is it only in shadergraph? or does it look yellow and green in the game and scene view also?
in scene as well
i got the transparent part to disapear but the white is yellow
this is scene^
not exactly sure but unless i'm missing something, i feel like it could either be a unity bug, or a bug or error with your gpu or the gpu drivers
it even happens when you create a new shadergraph?
is it possible that i'm using the wrong shader ? i'm totally new to shader stuff. just doing tuts
I also changed my pipeline asset to a custom 2D URP
here are the pipleine assets
maybe sprite textures are weird, i haven't used them with shadergraph
i know they aren't regular textures exactly
that's why the texture importer has an option for sprites, because they are unique in some way
I'm also new to game development so... ya i probably effed something up somewhere.. what would you double check first?
instead of using a sprite... what would you use?
this is a few years old but there might be a special shader graph type for sprites https://kylewbanks.com/blog/sprite-shader-effects-with-unity-and-shader-graph-part-1-getting-started
Shaders, those mysterious programs that somehow instruct the GPU how to render objects and effects in our games, are a great way to introduce effects that make your game stand out from the crowd. However it can be quite daunting figuring out where to start and how to write even the simplest shaders. They’re written ...
i literally just want to make effects using a circlular png or sprite whatever
i don't need to use sprites
Im in a 3d project
Sprite is just a nickname for the Texture2D
but yeah you could also not use what unity considers sprites, just a regular 2d texture on a quad / rectangle which is what i usually do but i work mostly in 3d
yes and no, in general game dev terms yes, in unity also yes but also a Sprite is a special "type" of Texture, that's why this is selected... as to how it's special i'm not sure
No I mean I nicknamed the Texture2D as sprite
In the shader graph
but in the "old days" have the alpha mask be baked into an rgb texture as bright green or magenta, etc was common
so that's what i'm wondering but just guessing
Check this out. so all tuts have showed something similar to this when creating a brand new mater shader. the only different is this whole "fragment" and "vertex" thing is't included. i'm thinking i might be using the wrong kind of shader as a starting point?
the tuts show somthing like a "sprite lit master" which i don't have
notice i'm plugging a v4 color into a base color 3 and taking the alphga and pluggin gthe alpha 1. that seemed to resolve the greeen parts of the sprite.. but i'm thinking the yellow issue has something to do with the weird fragment and vertex starting point
yeah they changed master nodes to vertex and fragment, but the shader graph has a certain type and target when you create it and in the properties like "lit" or "unlit" "decal" etc
sorry for linking to an old article
i'm testing something quick
ahhh wait... do i just need to plug in a color node into the base color 3?
i think this is working
that's one way to do it anyway if that's all you need. still weird this yellow green color
@lucid geyser i was going to say try this on the texture import settings
change from sprite to default
but that's just a guess
it maybe makes no difference, maybe sprite is just another way to tell the editor you want have the option to edit the texture pixel by pixel but doesn't change the texture format, so more to the point of what @clear veldt was saying.
wdymmmmmmmm
i haven't done much 2D sorry for going on with some wild guesses
when i select sprite as texture type it says i can install the sprite editor and edit sprites
anyway, sorry off topic
Oh, I haven’t had that
But I’m working on 3d
@lucid geyser even though you worked around the issue the yellow green seems strange. i would try restarting unity or restarting your computer at some point, and try updating the GPU driver to see if it persists or goes away. not exactly the same issue just little dots but bright yellow and green. the person updated their GPU driver software and it went away https://forum.unity.com/threads/weird-green-and-yellow-pixels-appears-on-textures.386844/
oh yeah true, well i haven't worked with sprites in the sense of unity's texture type either and they seem geared towards "(2D or UI)" according to the dropdown. so i guess that could be UI in 3d game. also is think particlesystem uses sprite type? but i mostly use vfx graph for particles and "default" texture type
Ok
thank you I will try to do that. I am using Memory profiler, and checking what it says.
this sounds likes normal default behavior in scene view in edit mode. unity tries to optimize some things in the editor to not run unless you are interacting with them. there are a few things you can do, enter play mode, and/r make sure "always refresh" is enabled in scene mode setttings, it's in a drop down that looks like a sparkle for "effects." there are also some editor scripts to force the editor to repaint every frame but they aren't really officially supported so might have strange results
i had a response to you about this already but i lost it i have to retype it lol. i was going to say, i'm not sure what your goal is, but it *looks *like you are (rail) "road building" and in that case i recommend using the Unity Spline tool package for this "road / world bending" on the CPU / in C# script land which will have fewer bugs and weirdness down the road (literally) than doing large movements of the game world "en masse" via on the GPU in shader land.
vertex position offset shaders like this should generally only be used for small movements like leaves blow in the wind, or MAYBE for some large movements that are only visual effects in the background like a thousand birds flying in the background that you never touch or electricity beams or sparks that fly right through you but you don't have any game logic attached to them. or maybe a weird world bending cinematic.. even then i would probably use the Mesh API and a script or compute shader instead of a vertex shader
assuming splines are the way here i think #🔀┃art-asset-workflow is the place to discuss the Unity Spline Tool further, i can see people have discussed it there.
https://blog.unity.com/engine-platform/building-better-paths-with-splines-in-2022-2
https://www.youtube.com/watch?v=CyN8Rw18_zw
https://www.youtube.com/watch?v=kNMu83sU948
Im not using splines, I have an endless runner so I just use a shader
My worlds already bends, some objects just float around
@clear veldt ohh because it's endless runner, the world coming at you is 3D but the player only interacts what's essentially a 2D plane. so it doesn't matter gameplay wise if the world bends in front of you with a shader. sorry for misunderstanding.
@clear veldt in this case i noticed a few months ago Unity released an official endless runner game example. i looked it up and it says it includes a "curved world shader". perhaps we can use this shader or at least cross reference it to your shader graph to help resolve the issue. https://assetstore.unity.com/packages/templates/tutorials/endless-runner-sample-game-87901
this tutorial related to the example says "The files to examine to see how this works are WorldCurver.cs, and CurvedCode.cginc"
https://learn.unity.com/tutorial/mobile-development-techniques#5c7f8528edbc2a002053b4ab
How can i make my shader sprite render behind other sprites?
for 2D?
yes, it doesn't behave the same as othe rsprites
i'm a person lol but i don't work for Unity. it's just a community forum
responding immediately with "this doesn't help" means you didn't even try. (or if you did find and try these methods earlier, i guess you aren't saying what happened or why it didn't seem to work?)
i recommend trying the first two methods in the doc. either put the sprite in a sorting layer and rearrange the layers so yours is in the back, or set the render queue for that renderer to a number lower than the other renderers
- Sorting Layer and Order in Layer
- Specify Render Queue
there's screenshots in there for how the sorting layers work even
it's linked from the 2D sorting article above https://docs.unity3d.com/Manual/class-TagManager.html#SortingLayers
Oh I think I’ll look at it
Does anyone know how to have multiple objects use the same shader but behave indipendantly of one another?
why do my textures look like this after sampling
you are presumably ignoring the alpha channel
Give them distinct materials that use the same shader
is there any performance cost of Shader.SetGlobalMatrix rather then setting them one by one ?
this tutorial telling me to use two kind of struct v2f, and for some reasons it works, but I don't understand how
InterpolatorsVertex MyVertexProgram (VertexData v) {
InterpolatorsVertex i;
UNITY_INITIALIZE_OUTPUT(Interpolators, i);
UNITY_SETUP_INSTANCE_ID(v);
UNITY_TRANSFER_INSTANCE_ID(v, i);
i.pos = UnityObjectToClipPos(v.vertex);
i.worldPos.xyz = mul(unity_ObjectToWorld, v.vertex);
// rest of code
}
but what I confused is that both use same name variable
both struct variable name is i
doesnt look like it
InterpolatorsVertex MyVertexProgram (VertexData v) {
InterpolatorsVertex i; // <----- I see only one!!!!
UNITY_INITIALIZE_OUTPUT(Interpolators, i);
UNITY_SETUP_INSTANCE_ID(v);
UNITY_TRANSFER_INSTANCE_ID(v, i);
i.pos = UnityObjectToClipPos(v.vertex);
i.worldPos.xyz = mul(unity_ObjectToWorld, v.vertex);
// rest of code
}
but then what is the Interpolators variable name?
based on the code you showed me, its not declared at all
UNITY_INITIALIZE_OUTPUT(Interpolators, i);
what does that function do, i would guess your answers lies there
oh... now that I look at it seems like the turtorial actually split the v2f vert (appdata v){} into multiple function
hahaha, catlike coding is it?
He does that, gives you the answer before the question and ur left guessing unless you read along
I recommend you do a quick read of the full page, then come along a second time
I see... thanks, I guess I need to reread it again
Anytime soldier, we are all in this battle together!
If you remove the inverse model and switch everything into world space (including the vertex node), that might fix it
Shadertoy (online) has lots of artistic shaders like that, they're in GLSL but the main difference is just that HLSL calls its vectors float234 while GLSL calls them vec234
not a shader question but,
you already did?
i'm sorry wrong channale
I’ll try
Greetings. I'm using standard pipeline on Unity 2020.
I'm trying to make a shader for a material on a cube.
I want the top face to be a certain texture, and I want the side faces to be a different texture.
I want it to tile based on x and z scale (but only on the top face).
I want the textures to be emissive. I want to be able to control the color, and intensity (values greater than 0).
I found some examples online, but they were all based on world position, and couldn't figure out how to do it just based on the local normals and scale of the cube.
YOu can do this with:
- multiple materials (requires your mesh is broken into submeshes)
- UV mapping (you will need to UV map your mesh such that each face uses a separate UV coordinate section)
With the UV mapping approach you can either combine all your textures into one, or do a mapping in your code where you figure out which UV section the fragment is in and then normalize the UV to fully map it to one of the input textures
can anyone give me some advice, i am trying to make a shader graph that is just turns a plane into a moving sine wave. ive experimented a load and i just cant seem to do it and cant figure it out. i have been told this is a relatively simple vertex shader but all i end up doing is changing the position of the entire plane or scaling the plane so I cant figure out how to individually change the vertexes to map to the sine wave. any pointers would be appreciated thank you
hey everyone! I have a beach shoreline inspired by Cyanilux's animal crossing twitter thread.
I have the waves flowing like in the first image in time. I'm using the second image as a mask to make it seem like the waves start off separate and combine to form one. However, I'd like to make it so there is variance. I dont want all the waves to start off as the same size. Does anyone have ideas as to how i could do this?
make sure to include the vertex's position in the calculations somehow or else all vertices will be affected the same
basically somethinbg like this is what you want to express in the graph, as an example:
vertex.pos.y = vertex.pos.y + Sin(time + vertex.pos.x)```
depending on what effect you want you may include the z position in there somehow too, or not
alright, is there a node to access vertex position? i presume it isnt vertex id/color
yep, the Position node
im trying to make a form of water for my boat project so looking at using gerstner waves eventually
is it one of these options or do i need to add extra nodes to the position node to access vertex positions?
I'm not familiar with gerstner waves but there seem to be many videos about that online
object is correct
or world
yeah i understand the mathematical concepts just trying to understand shader graphs now in order to oimplement them
basically it depends where this node ultimately feeds into:
- if you're feeding it into the vertex stage it means the position of the vertex
- if you're feeding it into the fragment stage it means the position of the fragment
we want a vertex shader here
im feeding it into the Postion bit on the Vertex
okay ill try test around more, ive been using the object position node before so ill see what i can do
im still not sure how to fix this. this shader graph is creating a flat plane and moving it up and down in a non linear scale and scaling it larger and smaller. also i tried using sine time and the same thing occured. i tried using the idea you wrote out here in code
the image is a bit too blurry for me to read properly
even when I "open in browser"
does that mean i could select any two of those and they would be equal to x and y since the vector position is less than four inputs?
not any two actually, the first two and that would be X and Y
The position is a Vector3, so there's also a Z component (aka B). RGBA=XYZW
In this case, for the Split it should just be 0 as there is no w component for a Vector3.
ah okay thats good
thank you soo much PraetorBlue and Cyan, i have done it, now for some minor adjustments
Also to add to Praetor's suggestion, you might want the result of the Sine here to only offset vertices along the vertical/Y axis. Can put it into a Vector3 node before adding to the original position to do that.
Though something to keep in mind for later, when doing actual Gerstner wave calculations they usually have some horizontal/XZ offset too.
i didnt know i could store them in vector3 variables, thank you very much. gonna be much easiser now i think
Just bumping my previous question
Clearly using Nsight to profile unity shaders is possible, as evidenced by this video, but I haven't been able to find any information on how to export shader symbols with a build
Unity's High Definition Render Pipeline (HDRP) makes it possible for developers to unleash their application's full potential using a custom renderer. With this great power, comes great responsibility; more than ever you need to ensure that your application maintains optimal performance so your users can have the best experience possible. Learn ...
hey Cyan! In your old animal crossing shoreline shader (https://twitter.com/Cyanilux/status/1251899743644549122) you have the waves starting off separated and combining as they get closer to the shore. I assume you're using a mask like the one i've attached. How would you make it so that the distance between these separated waves varies? So that the waves dont all combine at the same time?
I'm thinking offsetting the Y coordinate of that texture based on some randomness?
Hmm, iirc the mask I used was some worldspace mapped noise. Probably lerped to white over the UV.y so it leaves less gaps/holes closer to the shore.
Hey everybody, this is with built-in rendering pipeline.
I'm trying to set fog colors from a dictionary.
Setting the fog color beforehand in the editor and not modifying it in code comes out fine:
But as soon as I set it in code, look what happens, no matter what setting I change.
The fog is pure white, and I can't even go change it in editor! (Granted, it's because I'm changing it once per frame in an update function, but still).
When I debug, too, the fog is being assigned properly...
But it comes out as white.
Also I start getting depth errors with my billboarded sprites, but that's a whole nother issue.
Hi! I need to create a shader using shader graph that will procedurally generate a space background with stars. The main problem is that I have to use sprites of stars for this.
I will be glad if somebody could explain how to do this or where to search for guides.
Thanks!
Hi, what would be the command to toggle the doubleSided property at runtime?
I'm not sure where to look. documentation points towards this but there is no mention of it :/
I want to write shader in unity, but it does not create an error in unity, but it gives an error through visual studio, how do I solve it (visual studio is defined in unity)
Didn’t work, and wdym by vertex node?
Instead of sampling a sine wave you could try sampling gradient noise (or just two sine waves added together with different frequencies)
The node it feeds into with the vertex position, normal, and whatever else
If the vertex position input is still set to object space in the node inspector it's going to break everything when object space isn't world space (i.e. when something rotates) but if everything is in world space it should work
is there any reason I cannot connect these nodes
they have been connected in the past and now I cant reconnect them
Chains of nodes sometimes get "locked" to a specific stage (vertex/fragment). It's usually recommended not to mix them
ah alright thank you
is there a way I can take the height of the vertexes used in a shader graph and use them in a script?
Not really no. I assume you want it for something like bouyancy if this is still for water. The usual way is to replicate the displacement calculations on the C# side.
ah crap alright
thank you
i have decided i hate gerstner waves too
Hey, I have a wind effect shader graph and I'm trying to turn it into a wind vignette (wind effect around the edges of the screen), any ideas how I coulod do this
hey there
having an issue with a custom character shader, on mac it doesn't cast shadows and ambient occlusion draws on top of the character. on windows it's fine. seems like something going on with the camera depth buffer? anyone ever seen a thing like that?
Anyone know why my exposed shader graph properties aren't editable from the Unity UI?
In the image I have selected "Size" which shows it is "Exposed" from the Inspector but in the material everything is grayed out except for the Colors.
Where is the material asset located?
Hopefully youre talking about the filesystem, if so its /Assets/Shaders/WaterShader
Hmm... It just looked like a default unity asset to me being uneditable, so I assumed it's in some kind of protected folder. But I guess that's not the case.
I tested this on a Core RP converted to URP and a brand new URP project, saved in different areas so idk whats going on man! 😂
Shader Graphs automatically create a Material asset under them (in 2022+), which is uneditable but uses the defaults from the graph. If you want a material with different values you need to create a separate Material asset.
Wow youre so smart, thank you
And thanks for trying dlich!
Aha, so it was a "default asset". Didn't know that the shader graph creates a material for you now.
anyone know if it is possible to get a shader range property min value and max value?
is there an issue w/ using a custom shader uniform in a depth / shadowcaster pass?
set on the material e.g. material.SetFloat
as soon as i reference any of those uniforms, the depth pass for this material gets dropped. not in the framedebugger.
Anyone could think a better way to write this?
float xCoordsColor = i.customShadowCoords.x > 1 ? 0 : i.customShadowCoords.x < 0 ? 0 : 1;
float yCoordsColor = i.customShadowCoords.y > 1 ? 0 : i.customShadowCoords.y < 0 ? 0 : 1;
return xCoordsColor * yCoordsColor;
I just want it when i.customShadowCoords.x and i.customShadowCoords.y both value is between 0 to 1, it will give me 1 as value, else it will give me 0
Clamp..?
clamp? how do you use clamp for this?
Nvm. Misread the code.
Here's my lazy and shitty first thought:
float x01 = saturate(ceil(0.5-abs(x-0.5)));
float y01 = saturate(ceil(0.5-abs(y-0.5)));
float result = x01 * y01;
yeah... looks more expensive probably no 😅
I doubt it's more expensive, it's branchless 😄
hmm... maybe you are right
1 - saturate(abs(floor(x))) also an option for the equation.
You can have a play around with something like graphtoy and see if you can get it any better
I see... thanks
float result = 1 - saturate(abs(floor(i.customShadowCoords.x)) + abs(floor(i.customShadowCoords.y)))
ok found the answer
An other way ? 🙂
float2 t = uv;
t = step( abs(t-0.5), 0.5);
float result = min(t.x, t.y);
I was trying to avoid step. but there are lots of ways 😄
Any reason why ?
Similar without step :
float2 t = abs( uv - 0.5 );
float r = max(t.x, t.y);
r = 1.0-floor(r*2.0);
🤷 min(step(0, x), step(x, 1)) just chain a whole bunch of steps together, then you have the same solution has the first one but with a fancy function instead
In the position node, what does the Object and World actually correlate to?
Object space and world space
should have made myself clearer, what is object space?
https://unity.huh.how/programming/vectors/positions-and-directions the only part of this page on vectors I'm making covers just that. It's the same as local space
Does anyone know of a free dynamic culling system I can use that works with hdrp?
What type of culling ? Like occlusion culling ?
yup
I need it to be bakable during runtime and the only free solution I've found so far is onot compatible with hdrp
Okay. Well I don't know any runtime solutions, sorry
There is Entities.Graphics Burst Occlusion. It is part of ECS but it is open source if this matters.
Can give you insights maybe
sorry to be a bother, this issue is driving me crazy. i set up a windows dev environment to see what the frame debugger looks like on that side. i boiled down the shadowcaster to something minimially reproducible (well, in our project anyways):
Pass {
// -- options --
Tags {
"LightMode" = "ShadowCaster"
}
// -- program --
CGPROGRAM
#pragma vertex DrawVert
#pragma fragment DrawFrag
#pragma multi_compile_shadowcaster
// -- includes --
#include "UnityCG.cginc"
// -- props --
float1 _Distortion_Intensity;
// -- types --
struct FragIn {
V2F_SHADOW_CASTER;
};
FragIn DrawVert(appdata_base v) {
FragIn o;
TRANSFER_SHADOW_CASTER_NORMALOFFSET(o);
o.pos.y += _Distortion_Intensity;
return o;
}
float4 DrawFrag(FragIn IN) : SV_Target {
SHADOW_CASTER_FRAGMENT(IN);
}
ENDCG
}
on windows, the camera depth pass for this material appears in the frame debugger, the shader property is bound correctly
on mac, w/ the same exact code, this DrawMesh frame is missing from the depth pass unless i remove the reference to _Distortion_Intensity
Anyone know how to export shader symbols in a build?
(Just bumping my previous question again)
I don’t remember that it works for Nsight, but you can try #pragma enable_d3d11_debug_symbols
I did see that in the documentation, but it didn't seem to work.
The documentation also mentions it generates symbols for Vulkan, which is what I'm currently using, but maybe I should try a d3d11 build come to think of it
I was using Vulkan for Nsight GPU trace, as it doesn't support D3D11
If you are targeting Vulkan you can try to use newer DXC compiler: https://docs.google.com/document/u/0/d/1yHARKE5NwOGmWKZY2z3EPwSz5V_ZxTDT8RnRl521iyE/mobilebasic#
That's a good idea actually, I'll give both a d3d11 build, and a DXC Vulcan build a shot
Why isn't the material with emission on isn't emitting any light onto surrouding objects?
Emission materials by default represent materials that not follow to light energy conseravtion principle. I.e. those materials can reflect more light energy then recevie from all surrounding light sources. Those materials are not light sources. For more realistic look with multiple light energy bounces (in other words light energy emitted from object is applied to surrounding environment) you need some form of Global Illumination (GI)
So If I add a mild light source and raise the intensity value of the color on the material, that should make the material emit green light right? Or it woudl appear that way
small amount of light falling on the material which doesnt affect the cube much but the material will reflect more light than what is being received because of high emission intensity
is this how it works?
no you need to use global illumination
in other words
baked lighting
and it's generally not going to be realtime
I have realtime global illumination on
I think to receive realtime lighting from this, you probably need light probes?
In this video, we talk about 2 ways to use emissive materials inside of Unity! Learn both how to bake emissive lights for static objects and a method to simulate emissive light in real time!
LINKS
UNITY EMISSIVE MATERIAL DOCUMENTATION
https://docs.unity3d.com/Manual/lighting-emissive-materials.html
UNITY ASSET STORE
http://www.therealtimeessen...
even in this video he uses a point light i think to get it to actually work in realtime
can confirm after inspecting the compiled output for d3d and metal and they both include a shadowcaster pass compiled for the same set of keywords. on mac, the shader inspector lists "Cast shadows" as no. and if i log the number of passes in the shader, on mac in reports 1 and on windows it reports 2:
Debug.Log($"[shader] {shader} subshader {shader.subshaderCount} pass {shader.GetPassCountInSubshader(0)}");
wish unity were open source
pretty much at the end of anything i can imagine trying, running into the brick wall of whatever is happening behind the c# <> native shader bindings. no idea why unity is dropping the shadowcaster pass on mac.
How do I render 1 milion of 2D circle sprites facing always the player?
indirect gpu instance 1 million quads and make them face the player inside the vertex shader
I have a problem with indirect gpu instance... I was following a guy tutorial but I didn't understand a thing
for set vertex positions... have I to use a matrix?
struct appdata_t {
float4 vertex : POSITION;
float4 color : COLOR;
};
struct v2f {
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
};
struct MeshProperties {
float4x4 mat;
float4 color;
};
StructuredBuffer<MeshProperties> _Properties;
v2f vert(appdata_t i, uint instanceID: SV_InstanceID) {
v2f o;
float4 pos = mul(_Properties[instanceID].mat, i.vertex);
o.vertex = UnityObjectToClipPos(pos);
o.color = _Properties[instanceID].color;
return o;
}
I wanna use a float3 instead of matrix and float4 stuff... is it possible? I heard that float for vertex is necessary for not break the rendering... so is there a way to efficiently convert float3 to float4 in shaders?
does anyone happen to know of a shader graph node that will let me colorize an inputted texture? i want to be able to colorize images white but multiplying by the color white obviously just uses the original color from the image
How exactly do you want to "colorize" it?
by changing all the colors in the image to white, same thing you can do to textures in image editors
If you change all the colors to white, you'll get a completely white texture though...🤔
or shades of
Do you have a specific example of it from an image editor?
well colorizing in image editors does different shades according to the strength of the color, so i suppose its similar to trying to create a heightmap from a color texture
but ill screenshot 1 sec
original:
colorized white / grey:
I think that's just decreasing the saturation of the image.
ah really? ill try a saturate node then, cheers
No, saturate in shaders is a different thing afaik. It just normalizes the values.
I think you can use Colorspace conversion node to convert to HSV, then set the S(saturation) to 0 and convert back to rgb.
Ah wait, there's actually a "Saturation" node as well
This just replaces the colors. I'm not sure that's what you want.
Yeah.
thanks, i knew saturate existed....but not saturation XD
this opens up wild possibilities 😛
so I'm getting baked shadow by doing
indirectLight.diffuse = DecodeLightmap(UNITY_SAMPLE_TEX2D(unity_Lightmap, i.lightmapUV));
but what I actually want is toon like shadow, so... is there a away to bake like toon shadow (without any gradient)?
The lightmapper can't be customized (at least, not unity build in one) and uses some standard pathtracing to render GI and shadows realistically.
But to have a toony look to your shadows, you could apply some ramping to them, similarly as what is done in regular toon shading.
I see... thanks
in shader, is there any way to get/lerp over an objects bounds? As in like, have a shader effect isolated to its worldspace min/max bounds?
Ideally without passing in vector3s through a material property block
I can do that, but I was hoping the shader has access to the bounds directly?
oh object node has bounds 👀
hrm
how do I "get" the bounds in object space?
i guess i could do two transform nodes for min and max
i feel this a more basic math function could achieve this however
the output is pure white, but I am expecting a gradient from min to max
what am I misunderstanding?
are min and max bounds broken? or straight up just don't do anything? I am not understanding why the output is a solid color
yeah im starting to think these just don't output anything of any kind, nothing I do produces any values, useless and broken, actively misleading, poorly documented may as well be flat out lying by claiming to exist and offer this thing
the distance between min and max bounds is not 1 at every fragment so this obviously 100% is completely broken
how do I get bounds in shader? The object node is broken and returns nothing usable
like am I just stupid? how can this return 1 for every fragment, that makes no sense
If your cube's min bound is -0.5,-0.5,-0.5 and the max bound is 0.5,0.5,0.5 then I imagine their distance would always be exactly 1
I don't recall if it was local space or world space but the distance would always be 1 nonetheless
what about when im subtracting the fragment's object space position?
why would it be always 1?
I dont understand what I am doing wrong, I just want to have an effect isolated to the bounds of the mesh, no matter what bounds the mesh is
distance = destination - origin, but when I use min max bounds, I am not getting any distance
finally getting something, I still dont know why min max bounds isnt working or producing the result I expect
Bounds are two world space coordinates, so taking their distance doesn't produce a variable that would change per fragment
Like, they are points, not coordinate spaces
I may have something about this somewhere
thats immensely confusing, how can the world space coordinates of min and max not produce distance? like, its positions in world space, ergo distance between those positions would differ per fragment???
I'm starting to think that I am the stupid one, that it does exactly what it does but im too dumb to understand how to use it
The distance of example bounds points -0.5,-0.5,-0.5 and 0.5,0.5,0.5 remains the same regardless of when or where you measure that distance
so why is distance still identical even when I subtract object space positions from it?
that should introduce spacial coordinates if it doesnt already have that, right?
I mean obviously I am wrong because its not working but I dont understand why thats wrong
it also behaves completely different when done in world space coordinates instead of object space, which also makes no sense to me
world and object space coordinates are synonymous as far as I knew, the same calculation done in all world should return the same as done in all object space
I dont know why this is agitating me so severely and my agitation is only making it harder to comprehen
Hey I understood this before and now I don't!
yeah 
trying to show myself empathy and not get mad at myself for not understanding
I think it should be something like this, for a vertical 0-1 gradient
We just want the world position "stretched" between the lowest bounds point and the highest bounds point using remap
But something's wrong here because the gradient changes around even when rotating a sphere
It looks mostly right but when rotating a sphere the bounds positions shouldn't change at all, but it seems like they do
here is where I am at, about to test a sphere like you suggested, I only did cube so far
the output of mine
Ah yeah Bounds is in world space with no rotation
meaning bounds grows as it rotates, its size changes 🤔
oh yeah but it also changes on a sphere in mine as well 
the bounds of a sphere do not change by rotating it (in theory) so that's pretty wtf
Totally!
this is my guess at whats happening
that its treating bounds more like object space box collider even though it says its a world space min max
That explains the value change, and it's not incorrect that the coordinates themselves are in world space
But I didn't know that bounding boxes could rotate at all
Yeah me either
shaders can get the rotation, maybe we can do some kind of matrix multiplication to remove rotation before the calculation takes place?
I guess the reason is it refers Renderer.localBounds instead of Renderer.bounds
oh and we DONT have access to the rotation either 😬
Oof
I'd find some lazier workaround
Or live with localbounds
It technically works anyway
hm I am doing mine in manhattan distance which isnt technically working on my end
but I am not sure what kind of matrix multiplication I have to do to get all these values in the same space irregardless of any rotation or scale
i know matrix mults must be done, but not sure what matrix, and what elements, and when in the calculation
this looks close
@tight phoenix I think you can use this if you want a -1 to 1 space within your bounds on all axes, used in place of world/object position
So any noise nodes and such would be using these coordinates, not within placed among these nodes
you're only using the x value of the min and max bounds?
I am getting broken texture and pure white output from your logic there
Oops that's right
needs more work
Using world position and bounds, you can do a simple remap yourself :
remapedvalue = (pos - boundMin)/(boundMax - boundMin)
im also realizing that I cant use the position node at all because the position node has no concept of bounds, its just a value where 000 is the mesh dead center 
I will try this now
am I doing this right? the output is broken, in scene there is sorta a gradient but its not in manhattan distance and I no longer know 'where/when' to convert the distance to that
I am trying to get box bounds of any mesh, regardless of scale, rotation, position
in manhattan distance values so that there is no visible 'sphere' to the distance
where 0 is one corner and 1 is the other
The preview is broken, but what about the scene view ?
in scene there is sorta a gradient but its not in manhattan distance and I no longer know 'where/when' to convert the distance to that
BTW, if I'm not wrong, the manhattan distance should be the sum of XYZ of the divide node.
sum as in x+y+z?
Yes
this is sorta-kinda working but rotation is still affecting the output
I think the problem is that its in world space coordinates, and I need local object maybe?
Here's what I got :
The last divide it to normalize the gradient over the bounds (else the diagonal length is > 1)
ill try matrix convert after the divide because its still a vec3 there
Yes, but shadergraph doesn't provide local bounds out of the box, you will have to pass them through script
this broke it, so this was not the answer
can't local bounds be derived from the world bounds?
No, it is only the other way around
The local bounds is a bouding box aligned with the object rotation, and the world bounds is a box containing all the local bounds corners, aligned with the world axes
if world bounds min max change when the object rotates, can't you just do some kind of matrix multiply to remove that rotation before doing the calculation?
since world bounds and object bounds are the same if the object isnt rotated
But it will still not be the local bounds
Why wouldnt it? This is wrong I assume?
Sorry, I answered before this sentence. Indeed, when the object isn't rotated they should match exactly
And it should work :
does that account for rotation somehow?
I don't know how to get rotation in shader, net says complex things about matrix multiplication
Yes, transform node accounts for rotation
okay, trying that now
Now, it really only works arount the 0 rotation, you get axes inversion and other weird stuff happening when you rotate :/
output is still kinda wack and changes based on rotation
yeah I think the problem is that the world bounds are physically getting larger as it rotates
so it cant just be multiplied out since its bounds got bigger and not just changed spacial position
Because the world bounds change with rotation, and the world -> object transformation makes their values jump all over the place when you rotate
Yeah that
so I guess the sollution is.. don't rotate the mesh
which is not ideal
Just grab the local bounds from script and send them to the shader
yeah I guess Ill have to do that
I am making use of a lot of material property blocks in my shaders and Im getting concerned that when all of this is in a scene together that performance might tank
but maybe it wont and my worries are unfounded
now I just have to figure out which iof these 5 attempts is made to make use of the correct bounds
and then make use of those bounds correctly
well that works for scale and rotate, but not distance 
Is there a way to get screen depth in standard render pipeline?
I have min max bounds positions in world or object space now, but I can't figure out how to get back to where I was to get the manhattan distance 😬
immensely frustrated
frustrated to the point that I know I cannot solve this without help
and in knowing that, its basically prophesizing and becomes true because I wont solve it without help, I cant, Ill stop myself
or something
anyways ill just take lunch
If you have the min and max bounds in object space, it should be hard to get the gradient you want.
Can you share how you got this ?
private void PassBounds()
{
if (meshFilter != null && meshFilter.sharedMesh != null)
{
Bounds bounds = meshFilter.sharedMesh.bounds;
// Object to World space.
Vector3 cornerMin = transform.TransformPoint(bounds.center + Vector3.Scale(bounds.extents, new Vector3(-1, -1, -1)));
Vector3 cornerMax = transform.TransformPoint(bounds.center + Vector3.Scale(bounds.extents, new Vector3(1, 1, 1)));
// Object space;
//Vector3 corner1 = bounds.center + Vector3.Scale(bounds.extents, new Vector3(-1, -1, -1));
//Vector3 corner2 = bounds.center + Vector3.Scale(bounds.extents, new Vector3(1, 1, 1));
matBlock.SetVector("_BoundsMin", cornerMin);
matBlock.SetVector("_BoundsMax", cornerMax);
Renderer renderer = GetComponent<Renderer>();
renderer.SetPropertyBlock(matBlock);
}
}```
So, these are the object bounds world coordinates.
Note that instead of doing the maths, you could just use bouds.min and bounds.max
You'd better go to pass the bounds "raw" value and do the math in shader in object space
anyone wanted outline for 2d sprite? How its made
Oh so that's why they change when a sphere is rotated
That piece of info I was missing
good point
oh missed this originally, also good to know
{
if (meshFilter != null && meshFilter.sharedMesh != null)
{
Bounds bounds = meshFilter.sharedMesh.bounds;
matBlock.SetVector("_BoundsMin", bounds.min);
matBlock.SetVector("_BoundsMax", bounds.max);
Renderer renderer = GetComponent<Renderer>();
renderer.SetPropertyBlock(matBlock);
}
}```
In this version, https://docs.unity3d.com/ScriptReference/Bounds.html per this, what 'space' are min and max in?
the math performed in transform.TransformPoint(bounds.center + Vector3.Scale(bounds.extents, new Vector3(-1, -1, -1)));
is a black box to me
I dont know what those values are or how to replicate them in-shader, I could guess based on their names but I wouldn't be able to debug that if it didnt just work
There is no notion of space in the bounds object itself, it just represents a box
how can a box exist without space
even the term box implies space, my brain is short circuiting trying to comprehend of a box that has no space
Vector.Scale .... is just vector3 * Vector3
so this function transform a manually calculated bounds.min from local to world space
its not a box, its just two coordinate positions that a box could be extrapolated from?
Well, yes. Kind of 😅
You could represent a box by the min and max, or the center and extend. But it can be summed up to two 3D vectors, indeed.
And by "no space", I meant it is not bound to any local object or world space in unity, this depends on the context where it is called from.
Renderer.bounds -> world space
Renderer.localBounds -> local space
Mesh.bounds -> relative to the mesh coordinates space
But all of them a just a bounds data struct
spacial transformation and spacial coordinates and the lack of any coordinates at all are difficult 🫠
I now have this, which allegedly is the bounds, in object space, fixed to the size of the bounds no matter its position, rotation, or scale
does that look right to you?
I think so.
Should give you local positions in the range -1;1
seems correct yes
pictured: stepping the output
okay now to get the manhattan distance from it somehow
I know to get manhattan distance I need corner to corner, and if the output is -1 to 1, I just need to add/subtract then manhattan those I think 
From the center ? abs(position) and sum x+y+z
why is this wrong?
why would the distance be always exactly the same no matter what fragment I evalulate if I am evaluating from positions that have been offset?
the problem is the offset positions were all offset by exactly 1 and -1.. so the difference didnt change?
But then how do you offset not all ofit by all of it?
What is happening in this custom function ?
manhattan distance
Out = abs(v1.x - v2.x) + abs(v1.y - v2.y) + abs(v1.z - v2.z);
Oh, wow, that's a lot of math for something simple 😅
thats the result I got when I googled the formula for manhattan distance
how am I supposed to know its wrong :/
no where on the page said 'hey guess what this is actually wrong'
It is technically correct, but could be written in a more optimized manner
Sorry Ill try to stop being snippy
optimized or not its still outputting a single value no matter what the fragment is
and I dont know why
unless the reason is because I am adding / subtracting to every value, this no change is created
Hum, you node setup would just output abs(range)*3 as manhattan distance here
but then how am I supposed to add only to some fragments but not others
normal distance is also a single solid value with no distance
What manhattan distance are you trying to get here ?
min to max bounds extents
I wish I knew what I was doing, I wish this was easier :/
I wish I didnt have to rely on others to explain every single basic vector math 101
You are trying to get the distance from A+X to A-X => 2*X
am I?
I have no idea wthat that means
is that the mathimatical formula that represents min to max bounds distance?
What is X in this case? Min, Max, and ?
I guess x is the fragment
I'm just trying to explain what is happening in the lasts nodes setup you've shared, and why it is a constant value
This doesn't make sense 🤔
min and max are value, and bounds extents is max - min
Again, what is the distance that you are trying to calculate.
From where to where ?
you said the output is in a range between -1 and 1, ergo to get distance between min and max, I need to center my coordinates on -1 and +1 then get the distance between the two, so to move those positions over I added/subtracted Range from both, and then tried to get distance
I already said, from min to max bounds extents
said here when you asked me previously
vector +111 to vector-111, or whatever values are the min and max bounds
And I said that this has no sense. You can calculate the distance from the min to the max of the bounds (which is a constant), or the extends, but "min to max bounds extends" means nothing
how can the distance between the furest point and closest point be constant
its a box
boxes are not constant width
This is so incredibly confusing, I have absolutely no idea why or how a box doesnt just have dimensions, a box is a 3d shape
I dont have comprehension
I dont have understanding
a box physically cannot NOT have dimensions, box by definition is a 3d shape, just like square is a 2d shape
Im sorry this must be frustrating that I don't understand
the box, like the bounds ? The bounds is a box, and it size is constant
I have no comprehension on what you just said
you may as well be speaking darmok and jilad at tenagra, I understand each individual word but the do not add up to understanding to me
the box.. is bounds? bounds is a box? size? is constant?
How can size be constant
Bounds, also know as "bounding box"
a box is a 3d volume, size and constantness dont even exist in 3d space in that sense
Bounds : a 3D box, aligned to some coordinates system, that encloses a mesh vertices
Yes
so why is this basically impossible
It is not
then why havent we solved it already
If you measure the box from one corner to another corner, you'll always get the same result for that box
That we talked about originally
if its not hard, why has it been hours
Sorry, I should stop whining, you're trying to help me
But in you node setup you're not calculating any valid distance, and you were unable to explain what distance you are trying to calculate
unable to explain what distance you are trying to calculate
bounds is a box
boxes have dimensions
I want the distance from the minimum positino of the box bounds to the maximum
I dont understand why you keep asking me to explain what I want or saying I cant explain it
I want an output of values that go from 0 to 1 across the box from the min to the max of the bounds, in object space, also known as the distance
Ok, so you want the distance from the minimum bound value, to the maximum bound value ?
This is the extend X 2, and is constant
that doesnt make any sense, this is where you're losing me
Ah THIS is something else.
You want the distance from the current pixel position to the minimum of the bounds
I think the problem is you are telling me the exact literal answer to my question, and NOT telling me what I ACTAULLY want to know
but I cant ask you what I actually want to know because I'm too stupid to even know myself and if I knew i wouldnt be here
im sorry im inexperienced
I'll ellaborate on this one.
You already have the normalized position. In the range [-1;1]
You just have to transform it to the range [0;1].
A simple remap node or value = value * 0.5 + 0.5 will do the trick.
Then, from this, calculate the manhatan position (values are already all positive, so it is just x+y+z)
It will give a result that ranges from 0 to 3, so finish by dividing by 3 to normalize the value
You were giving me the exact symantic answer my question, but my question itself was wrong, the words I was using to explain my queston were not the right words, but in my mind they were the right words because I had no possible way to know that I was not asking the question I was asking
reading this now
I have an additional question : why the manhattan distance specifically ?
because I want the values to act as a mask to an effect to resolve in all directions linearly rather than across the true distance where point to point is the furthest real distance
which, is also wrong, and dont listen to what I just said
because I do not have the language to explain what I want in words
and the words I just spoke do not represent what I want
I will draw it instead
because drawings are a language we both speak
that is manhattan distance, correct?
This can be done with min
(nope)
But you can do it with min nodes.
result = min(x, min( y, z ) );
okay so the whole time I wanted Chebyshev and not Manhattan
every time I used the word manhattan, I meant Chebyshev
You know more mathemical term than me 😅
yeah I dont evne know how to say that kind of distance without using its 'official' name
Note that your gradient in the picture goes from white to black.
If it was the other way around, you'd want do use max instead
distance where every direction is the same distance? distance where.. diagonals are not normalized?
like I cant even describe it, its just 'chebyshev distance'
Anyways this is a wild tangent now, I will try to impliment again based on this
Acoording to wikipedia : distance between two points given by the greatest single dimension difference
If I would to put in my wording
this part - back on my earlier confusion, why is distance constant?
its because the min and max are positions, and the distance between them is a single value?
Every time I said min and max extents I meant its 3D world position to its opposite 3D world position, is the problem that the words I used to ask for what I want, the meaning wasnt interpreted the way I intended?
except what I just said above is ALSO wrong isnt it?
I didnt mean its 3D world position to opposite, I meant the fragment's position on the mesh... <something something something related to the two corners>
which is what this is
I feel like the problem was ultimately not that I didn't understand, the problem is that I couldn't explain what I wanted correctly
the words I kept using were describing something different from what I meant to be asking for
unless thats wrong too
There is no "min and max extents".
For a bounds, you have two pair of intricated values : min / max and center/extends
The bounds for an object is constant (that why you only pass the bounds values to the shader a single time), so it will always result to the same value for every pixel
because at this point im pretty much settled that im always wrong and know nothing
...How??? How can there not be min and max extends? That already makes no sense right away
here is why my brain doesnt understand
a box has physical dimensions
I can touch two places on the box
ergo there can be a min and max
It's just terms and definitions.
Extents is the half diagonal of the bounds -> a dimension
min and max are positions
the min being the lowest possible spot on the box, and the max being the highest possible spot
for a line its easy to visualize because lines have a start and an end, so for a 3D volume of a box its like rotating a diamond
"lowest" and "highest" in all 3 dimensions, but yes
in this picture, is this picture depicting the min, the max, and the center?
Figure them as the corner with the lowest values in all dimensions, and the corner with the highest values in all dimensions
which is 'extents' ?
Yes exactly thats 100% what I understood this entire time
Half of the diagonal that goes from min to max
What I am not understanding is why did it take this must time and effort to get to this point
like, It feels like we agree on everything, but then I go 'then x = x?' and then you go 'no, x = apple'
and I am just not grasping
thank you for your patience with putting up with me as well
min and max, lets pretend they're world coordinates, are (000) and (111)
Because there is so many weird stuff that is possible to do with shaders that if you don't state clearly the intend, it can easilly be misinterpretted
which is what i understood, what you just said, lowest and highest possible
yeah 🔥 😿
I should stop trying to 'understand' it for now and just get on with it
I havent even tested if this works yet for example, by works i mean 'does what I want'
and center is (0.5, 0.5, 0.5) and extends is also (0.5, 0.5, 0.5)
I'm trying to explain why all that confusion.
Taking you example, min=(0,0,0) and max = (1,1,1).
Quoting you previously :
I want the distance from the minimum positino of the box bounds to the maximum
Well, to my reading, that's distance between min and max, so a constant square root of 3 🤷
The importand point was this :
I want an output of values that go from 0 to 1 across the box from the min to the max of the bounds, in object space, also known as the distance
Because the thing that is displayed across the box is the curent pixel, which is the element that has a variable position value.
it seems to be working
So, are we all good now ? 🙂
🫠 almost
I cant help but notice that after all that work, the outcome looks suspiciously like object position
is object space position ALREADY values 0 to 1 of the bounding box? did I just waste hours on something I already had?
For a single unit cube, yes, it is the same.
But for everything else more complex, it won't
whew okay time justified
like this cylinder for example
huh interesting that its bounds corner is here
I guess it makes sense the bounds would be on the mesh and not on the box bounds?
or am I dumb and this entire time I wanted object position
Not exactly here, the bounds corner will be outside of the cylinder
It is basically a remapped object position
remapping its range to be 0 to 1 in object space instead of whatever length of real units it takes up 
bounds-normalized, so to speak?
Yes 🙂
Saying that now, it could have been done with a single remap node 😅
Well, if remap was working for Vector3
Anyway, you got it working, now up to you to do something with this gradient
yess
remapping of what? 👀 💦
remaping the object position
how would I remap its object position to 'bounds space'?
since 'bounds space' doesnt real
is it this bounds size value
sorry, by "object position", I mean "position node, object space"
right, i understood that, the part I was asking is how can I remap this in a single step?
to get the same result?
since it sounds like if I can remap it in a single step that will be much more performant than passing bounds in through material property blocks
and then doing a shitload of math
You still need the bounds data, but it can be done with fewer nodes
oh okay
the property block is the slowest bit so in that case nothing really changes
result = (position - min) / (max - min)
And that was my initial answer when I joined the conversation 😅
and the only reason it didnt work was because we were using the min max from the object node, instead of its real min max from its real bounds
Yep
Okay, the fact that I was able to understand why that was the case is reassuring
yep result is the same
okay going with the optimized vesion, ill keep the old version as a backup just in case
Why the multiply by 0.5 after it ?
Thanks for all the help, I know it wasnt easy to get through to me
without it, the range is from corner to mid point instead of corner to opposite corner
Is this not the expected output?
No, it should just range from 0 to 1
maybe because object space starts centered?
granted I had to do the *0.5 even before using object space
Nah, that's the whole point of remapping with the bounds min and max 😄
Can you post a readable screenshot of the rest of the connected nodes ?
Yup 1 sec
both required the 0.5 mult going into Split
original pre object space method output without 0.5 mult
Hum, nodes seems correct, so the only source of error I can think of are the bounds min and max values.
Did you change the code ?
I dont think I did
that code runs OnValidate and Start so its up-to-date
Oo.
This is somehow unexpected.
For a defautl cube, it does display -0.5,-0.5,- 0.5 and 0.5,0.5,0.5 right ?
oh uhh yes
erm
mnaybe?
in the picture, that is a default cube
https://cdn.discordapp.com/attachments/497874081329184799/1133829951716605972/image.png
this picture those are all unity stock primitives
What did you set as default values for those variables ?
oh before passing in? 000 and 111 for min/max
or do you mean in the script?
in the script I didnt set any default values at all
IDK, both, I'm confused, if the script is working properly it shouldn't display like this XD
HAha
as usual, pebcak
Happens
There should be an error logged in the console when the property does not exist
Nice, finally all fixed and working properly, now go do what you want with this gradient 😄
trying to make use of the output to create a directional mask that I can pass from point to point but so far I cant even seem to debug one
Im so @#$@^ing burnt out that I can't even do the most basic thing but im still on the clock at work even though ive done basically nothing deserving of being paid all day :/
iunno why im even posting this
i am miserable and cant stop feeling imposter syndrome
spoke too soon, its actually working exactly as desired right now
wow
I'm just so burnt out I can't even feel joy that I got it 🪹
How can I make one of this that has the unity those squares
if thats asking me how to make the above mask, I am not sure what you mean by that
from the publisher
hm the janked up edge appears to be occuring due to floating point problems, bounds to shader says its a weird shape
ill work on this more later because im too burnt out to know why anything is anything
I mean that because of how square it looks
Your question doesn't make sense?
So I've seen these before, know what they are for, have used them before, but was wondering.. does anyone know what these would be called?
can give context if needed
That could be helpful
it's basically three images in one, red is one image, green is another, and blue is another.
you would get each different image by getting the different color values
Would be called something along the lines of channel-packed masks I guess
ohh
yeah that makes sense
https://youtu.be/jlKNOirh66E?t=267
Found a video containing a better explanation if needed (timestamp)
It’s shading time. Watch me try to make a shader that renders real-time 3D in the hand drawn style of Moebius. There be crosshatch, outlines, sobel filters, we’re in for a bumpy ride.
Support the channel on Patreon to get extra content, and access to the Discord server and to the source code of every project!
https://www.patreon.com/UselessGame...
HDRP utilizes this notably
https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@14.0/manual/Mask-Map-and-Detail-Map.html
Functionally it's no different from separate textures, but cheaper
I know what it's used for but was curious as to what it's actually called
anyone know what this means?
only seems to happen if I input a Vector4 in UV.
but it still happens if I switch UV from Vector2 to Vector4
and this is the subgraph
and finally, this is line 58
just noticed these errors
If you replace the Texture.Sample with Texture.SampleLevel and specify a mip level like 0, then the first error should not occur, which means the compiler won't unsuccessfully try to unroll the loops.
Hi guys, can you help me with this URP shader? I have a URP Lit material, and my goal is to change the tile value of the '_DetailAlbedoMap' in runtime. I've implemented the following code to achieve this:
internal void SetTexture(Texture texture, int tileSize = 10) {
baseMaterial.SetTexture(detailAlbedoMap, texture);
var tilingScale = new Vector2(tileSize, tileSize);
baseMaterial.SetTextureScale(detailAlbedoMap, tilingScale);
skinnedMeshRenderer.materials[0] = baseMaterial;
Debug.Log(baseMaterial.name);
}
The problem I'm facing is that although the value gets updated, the changes are not being reflected in the game's renderer (mesh) until I make some small changes in the editor. Is this a bug, or am I doing something wrong?
how to override a function in hlsl?
like let's say I want to override BRDF3_Unity_PBS, only in one specific .cginc file is possible to do so?
I am working on custom lighting/shadows in URP unlit shader graph. I have it working with the directional lights and point lights (I think point lights don't have this issue since the shadows are cast in 6 directions).
Spotlights give horrible shadow artifacts when the shadow is at the edge of the light's bounding box. Does someone know the reason for this and how to solve it maybe?
void AdditionalShadows_half (half3 WorldPosition, out half ShadowAtten){
ShadowAtten = 1;
#ifdef SHADERGRAPH_PREVIEW
ShadowAtten = 1;
#else
uint pixelLightCount = GetAdditionalLightsCount();
uint meshRenderingLayers = GetMeshRenderingLayer();
// For Foward+ the LIGHT_LOOP_BEGIN macro will use inputData.normalizedScreenSpaceUV, inputData.positionWS, so create that:
InputData inputData = (InputData)0;
half4 screenPos = ComputeScreenPos(TransformWorldToHClip(WorldPosition));
inputData.normalizedScreenSpaceUV = screenPos.xy / screenPos.w;
inputData.positionWS = WorldPosition;
LIGHT_LOOP_BEGIN(pixelLightCount)
Light light = GetAdditionalLight(lightIndex, WorldPosition, half4(1,1,1,1));
#ifdef _LIGHT_LAYERS
if (IsMatchingLightLayer(light.layerMask, meshRenderingLayers))
#endif
{
ShadowAtten *= light.shadowAttenuation;
}
LIGHT_LOOP_END
#endif
}
I have problem with setting Color to my shader. It doesn't changing.
var materialProperty = new MaterialPropertyBlock();
materialProperty.SetColor("_SelectColor",new Color(1,1,1,0.95f));
_lastMeshRenderer.SetPropertyBlock(materialProperty);
Changing for example SunlightLevel work fine.
why my cutout shadow caster? anyone got an idea?
how to make real time cutout shadow?
shadows are cast in a special pass that is rendered from the perspective of each light into a shadow map. Specifics might vary a bit by pipeline.
So you'd have to have the SHADOWCASTER pass render your object not as it's default, but as its cutout. So you can't use a default shadow caster pass, you have to include one in your shader. If using SG, you'd have to do that by hand, editing the resulting code-generated file, as I don't know of a way to do it in the tool (I think). That's why you're getting a quad, because that pass isn't doing the cutout calcs.
Custom geometry mods/discards are always a problem with shadows.
I do have them in that shader code, here the frag
float4 MyShadowFragmentProgram (Interpolators i) : SV_TARGET{
UNITY_SETUP_INSTANCE_ID(i);
#if defined(LOD_FADE_CROSSFADE)
UnityApplyDitherCrossFade(i.vpos);
#endif
float alpha = GetAlpha(i);
#if defined(_RENDERING_CUTOUT)
clip(alpha - _AlphaCutoff);
#endif
#if SHADOWS_SEMITRANSPARENT
float dither = tex3D(_DitherMaskLOD, float3(i.vpos.xy * 0.25, alpha * 0.9375)).a;
clip(dither - 0.01);
#endif
#if defined(SHADOWS_CUBE)
float depth = length(i.lightVec) + unity_LightShadowBias.x;
depth *= _LightPositionRange.w;
return UnityEncodeCubeShadowDepth(depth);
#else
return 0;
#endif
}
The important part is just the clip(alpha - _AlphaCutoff); right? for this? but it didn't work for me on real time, but it does work on baked
Hmmm...IDK. Verify the pass name. What pass is that code in?
Unity standard shader can do this on real time, but I can't really understand what my code lacking
IDK off the top of my head. But if you're getting that quad, I'm thinking that some other condition needs that clip function call. Or "dither" doesn't have the value you think it does at the time.
You could try returning something else, like 0 instead of clip, but I"d assume 0 is the default.
GTG....work calls. 😉
damn... I'm dumb
_Cutoff ("Alpha Cutoff", Range(0, 1)) = 0.5
I forgot I changed my _Cutoff name
took me 2 hours I want to cri
is it possible to clamp the slider between 0 and 1 but if I want to I can still type like value of 5 manually?
Hey I have a question
so im trying to make a blend slider to slide between textures and Im having a bit of a problem
I tried making a frenel effect with the texture that'll be slided in and for now defaulted it to a normal color
for the slide in I used a Uv node and split it to take out it's Y axis value to perform the slide along the Y axis then connected that to the opacity of the blend node
it's having weird blending outputs. the blend mode is set to Overwrite so I have no idea why that is
I tried using normalise but it's still not working right
can I send a picture because I feel like that'll better explain it
That shouldn't be possible unless u create a script of some sort to handle the clamping and expand the clamping range if certain conditions are met
2 textures
I see... I guess I will give up using slider
better send picture I guess, I don't don't really understand your question. so like you want to blend 2 albedo texture then give the material a fresnel effect?
yh
one sec
i want the new texture to slide in like it's showing on the multiply and normalize nodes
but it's not
im currently just using the color blue to represent the texture
I don't really understand what you mean by slide in
Ive nv used blend node, literally just heard about it and wanted to play around with it
nvm then
tnks though, I'lljust learn something else
I think I'll wait for cyan to come on or something because thinking about the things I could do with that, my desire to learn it is peak rn
The terms "texture to slide" are pretty hard to understand :/
is there no way to force gpu instancing to take more than 2 pass?? :/
does creating heartrate using shader worth the effort (performance wise) than creating it using particle?
Depends on the exact shader and particles used.
I expect shader graph to be faster, since everything can render onto 1 quad, instead of multiple quads for particles. This saves vertex shading, and batching, in exchange for some higher pixel shader costs
i see, but, isnt it like, heavy math if i want to create this shader
guess i need to learn math again lol 
Shaders if written properly are very efficient.
I don't think a heartbeat will be too demanding
But for now I'd say pick which is better for now. Unless you do something crazy both won't kill performance probably
thanks for the info 
guys im really struggling to figure this out and i feel like im losing my marbles --------> https://forum.unity.com/threads/how-do-you-find-the-lowest-value-of-a-texture-sampled-at-different-locations.1465952/
What does it mean that the greatestHeight gives different values for different index ?
thats the million dollar question. it makes no sense. how can greatestHeight not be the same number for every value of index?
I'm trying to understand how you know that it is not the same number.
Since for each index you sample a new heightmap value, if greatestHeight was updated before, it would make sense that it is different for each iteration of the loop
let me clarify. when i write the output to a texture then i get different values at the different uvs passed in _ArrayCoordinatesOfSplats
Well, you are sampling the heightmap at different UVs for each value of the array, so this is not suprising ?
Oh, or maybe you were expecting that greatestHeightAtSpotLocations is a common variable shared between all the pixels ?
yes. isnt it common to all index values?
does this look like clouds or more like water ?
for me it's looks like cloud, simply because of the color and how it didnt transparance enought for a water
i dont know about the view when you near to it tho
In the context of the code you've showed in the forum post, it should be common for all "index values" when executing the loop.
good, because it is a cloud but a lot of people say it looks like water and heres a picture from a bit closer
yeah, now it's really looks like cloud
What I REALLY don't understand is how you know that greatestHeightAtSpotLocations changes for each index, since you can really read the value only after the loop executed.
And how do you do to debug it in an output texture ?
i write 'greatestHeightAtSpotLocations ' to a rendertexture after the loop executed
And so, the RT is not a solid color, the value varies for each pixel, even though the array coordinates are constant ?
i see now something strange is happening when i blit the RT to a temporary RT and then that temporay one back to the RT
?
when i draw red pixels to the RT and then blit that RT to a temp and from the temp back to the RT those pixels arent red anymore. They're grayscale.
How do I get world space values that will allow me to lerp between top and bottom in world space from its bounding box in shader?
the space I thought I needed it in proved to be wrong :/ so now im back to square zero
i still can't wrap my head around the fact that min and max are not points in space and I can't just lerp between the two points in space
is there some way I could just write a subgraph to MAKE them points in space so that I can do this
because every single time I go to use them, I need them to be points in space I can lerp between but they arent so I cant
i can feel my distress already rachetting up because I need this done, I need this solved, I need it solved yesterday but I am no closer to a sollution and I can't do it on my own but I need to get it done so I am a failure who has to rely on others to help me and if I can't get help, im fucked
@Remy it looks like it has to do with color formats
should i srgb on any of my texutres or must i stick with UNORM?
It depends on you heightmaps format, you should use the same
So, vertical gradient based on min and max bounds ?
result = (worldPosition.y - min.y) / (max.y - min.y)
Min and Max are points in space. But they are constant values for evey pixel of you object. So if you lerp between them with a constant mask value, you still get a constant value.
I tried that, it didnt work
this didnt return a value between 0 and 1 from top to bottom, the masking didnt 'scale' it was still linear
@amber saffron when i blit the source heightmap to the RT then the colors display correctly. But when i blit from RT to temp and the from temp to RT all the colors are grayscale.
Really ? It should (unless the object is rotated, then we gent to the local/world bounds issue again). How does it look in the scene ?
the object is rotated/
I want world bounds this time, I was wrong yesterday, local doesnt work atll for what I need
Then the min is probably a bit lower that the lowest vertex of the object, and the max is probably a bit higher ... and this is expected
I spent the entire day wasting everyones time and being a failure and ultimately the result wasnt even what I needed because as usual I am too stupid to even know what I need b
@amber saffron i use R8G8B8A8_UNorm on all RTs and UnityEngine.Experimental.Rendering.GraphicsFormat.R8G8B8A8_UNorm on the temp RT
I am in crisis and I cant handle this but I HAVE to immerse myself in this agonizing acid because its my job
sorry
Weird :/
i should shut up
i cant handle being a failure but game dev every 15 minutes you're failing at something
Are you expecting the gradient to go from black to white from the lowest vertex/pixel to the highest one, independtly of the rotation of the object ?
Yes
I want a float value where 0 stepped is fully masked out top to bottom, and 1 is fully masked in top to bottom
Won't happen then unless you recalculate the bounds yourself each time the object is rotated then.
no matter what size or rotation the mesh is at
okay so I can pass in that bounds again from the script, except per frame instead of once
Not enough
what why?
Let me try to sum up this :
- You want the world minimum and maximum Y of the mesh, whatever the rotation and scale
- You can not use either the local nor the world bounds, as :
- The local bounds will outshoot minimum and maximum when the object is rotated
- The world bounds mush encapsulate the local bounds, and will also always outshoot
So you need to calculate world bounds (or min and max Y at least) each time the object is scaled/rotated, by taking in acount all the vertices world position
And this can prove quite costly if you have a lot of objects with complex meshes
😰
I don't understand why its so difficult or costly, its frustrating because in real life its incredibly simple to say 'here is the top and bottom of something'
like I am not trying to write code for it to identify what is or isnt a bird in a picture, I just want the top and bottom
trying not to panic
Because cpu and gpus don't work like you brain, and realtime rendering needs as fast as possible (so as simple as possible) calculations.
The mesh bounds is calculated once, when the mesh is imported.
It then can be summed up to 8 points : the corners of the bouding box
The world bounds is calculated in realtime by quickly calculating a box aligned with the world coordinates that includes those 8 points.
This is very fast, compared to having a more precise bounds for meshes that coulds contain million of vertices
