#archived-shaders
1 messages · Page 46 of 1
I did not expect having a pure black colour on the top there to just work
only got 2 textures and seems to work so far, but how would i use the last vertex color channel?
i could add extra lerps for the base diffuse just offscreen to the top but i could only connect it to its own heightmap
what are you trying to do
its basically just a shader to paint vertex colors, and use heightmaps for blending
so for each vertex color you use a different texture?
yes
tbh. I have never seen vertex color being transparent, why would that be something you want to add?
to my understanding its just another channel, and it has nothing to do with transparancy
polybrush uses the alpha channel aswell, its just another texture
ah well, yes it is, well why don't you do what you allready did make another texture and blend them toghetter with lerp
basically because i'm short 1 lerp node, the ones i have here are all used to lerp the textures together, and the heightmap gets added as a mask, but for 4 textures to lerp you only get 3 lerp nodes. so im unclear what to do for the base texture
(3 lerp for albedo, and 3 for normals)
i'm also unclear on what the normal and blend on the triplanar node are for, i couldnt connect my own normals to them
blend is how smooth the transitions between each side should be
Short question, I've got a default Unity unlit shader, where everything's default, but the fragment shader outputs a color value:
{
return float4(0.1529412,0.07843138,0.08627451,1.0);
}
As a result, this is the output:
However this is the color value for that code
ahh, i already got a float connected to the masks. to controll all blends at once, im guessing i could use the blends on the triplanar node to blend individually
what's wrong?
from where do you have that color
Photoshop
Color picked from a palette
Oh also with GetPixels() from Texture2D for that matter
and I am guessing color was displayed from 0 - 255, how did you convert it to range between 0 - 1?
I did both GetPixel() and GetPixel32() (the latter for easy debugging)
If I make a simple shader with similar values in ShaderToy (GLSL) it does output the correct value
Ah, switching away from linear space to gamma space solves the issue in Unity
why is that?
ah well good old gamma correction
in gamma, colors are interpreted non linearly
what do I read to understand what linear vs non linear means?
maybe this helps clear up what im trying to do
hehe that was in regard to my own issue @tender edge 🙂
ow sorry misclick, didnt mean to reply
what are possible causes why sampling the unity shadow texture has a weird bright spot that exists a certain distance away from the camera
i need this data to not have that weird spot in the middle
its ruining the entire shader and I have no idea how to prevent it or even find its origin
im really struggling and could really use some help, ive been working on this for weeks and have made zero progress
Can you suggest somewhere else to ask for help? I feel like I reach so few ears here but I can't seem to reach ears anywhere no matter where I post
I am sorry to hear that, I haven't worked much with the shadow texture so I probably wouldn't be much of a help. You could always try asking on the forum
Not sure if someone can helpme, but I have a problem with PSXEffect shader texture, when using multiple rectangles as floor instead of a big one I have this problem (shadow on player becomes black), any one know how could i solve this?:
I tried that but ill try again
hey which is more optimized approach? , Im trying to understand how shader/memory works
1 - make arrays from 2-10 in a shader and only pass the one I need to the function ?
2- just make 1 array of (10) items and pass it everytime even if only 2 items were occupied were the other 8 empty?
??
I'm getting a shader error with a Blit shader:
'SampleBias': no matching 3 parameter intrinsic method...
For the line of code:
float center = SAMPLE_TEXTURE2D(_BlitTexture, sampler_BlitTexture, uv)
This error only occurs during the build process, and the shader (used in a renderer feature) does work in the editor
How would you split a texture red channel into 2 ranges? (range1 = 0-127, range2 = 128-255)
I'm using a Split node, then remap 0-0.5 as my range1, but I'm not getting the expected output ...
is this not what you'd expect?
I'm trying to get this output
⚠️ When asking questions please include which render pipeline you are using ⚠️
🗃️ Documentation
Shader Graph
Surface Gradient Bump Mapping
📚 Resources
RenderDoc
Homepage • Unity documentation
Tutorials
External resources: General
External resources: URP
External resources: Shader Graph
- Intro to Shader Graph
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
You can try shader coding outside Unity with:
Shadertoy (online) or Kodelife
Graphtoy also helpful for shader maths
💬 Forums
🗺️ Roadmap
maybe two comparisons?
Thanks @vocal narwhal and @tame ingot both the step and comparison methods are working.
Hi, I'm following a tutorial for learning some particle system type stuff with HDRP. The tutorial says to enable the Allow Material Override option but I don't seem to have that option anywhere on my Graph Inspector as the tutorial does.
Am I supposed to find this option somewhere else or how do I go about this then?
[MaterialProperty("_Emission")]
public struct MaterialEmission : IComponentData
{
public float3 Value;
}
Shader error in 'Master': 'LoadDOTSInstancedData_float3': no matching 2 parameter function at line 1021 (on d3d11)
Shader error in 'Master': undeclared identifier 'unity_DOTSInstancingF12_Metadata_Emission' at line 1021 (on d3d11)
https://media.discordapp.net/attachments/1064581837055348857/1105170509584404480/image.png
I created this thing, and set the shader graph property's override to Hybrid Per Instance, as well as Allow Material Override on the graph settings, however there are shader compiler errors. Not sure where to look.
It was because the graph's precision was set to half , when set to Single it works fine 🤷
I'm trying to find information about the structured buffer limitations for a compute shader but I can't really find anything. How many structured buffers can you have in one kernel for modern GPUs on Windows?
I have 10 structured buffers atm and it's starting to do some weird stuff, like crashing NVENC in OBS.
until memory runs out i guess 😛
So I have a sea shader in my game
But as soon as I move to the right, it goes invisible leaving a highlight around the objects its hitting
If they count as UAVs (which I think they do?) then the Direct3d-11 docs have D3D11_PS_CS_UAV_REGISTER_COUNT, which has a value of 8. https://learn.microsoft.com/en-us/windows/win32/direct3d11/overviews-direct3d-11-resources-limits
Happens in editor and game view
you should show us your code
@regal stag do you think this limitation is still present in the experimental branch of DX12 in Unity? That's what I'm using atm.
There is no code.
but 8 would track with my amounts where it started acting up
I'm trying to check that too. Seems to be info on this wikipedia page but I don't fully understand it. https://en.wikipedia.org/wiki/Feature_levels_in_Direct3D#Direct3D_12
Seems to be different tiers, 8, 64 or full heap
Yeah I've found the tiers but I didn't quite understand what constitutes as a tier
i guess DX11 cards are tier 1
my card supports 12_1 and 12_0 so i guess that should put it in tier 2 resource binding
Are there multiple water planes here? It looks like two transparent planes not sorting correctly.
Seems I had to manually set pragma target 6.0 maybe. Doesn't crash now but not sure if it works.
I guess Unity defaults to target 5.X for compute shaders
Can I use CGPROGRAM in shader graph?
No
Nope, just one…
I am trying to create shader for my text box similar to this image. I can able create border and inner glow for square but not for rectangle any suggestion.
Thanks in advance
hey,
is it hard to get the vertexes of a shader shape? for example
is it possible to get the outline vertexes that makes those shapes ? if yes , how hard could it be ?
im currently learning shader and i wonder if there is a way to create an outline of any shape like the ones mentioned above and get the vertexes that creates the shape
You mean in the vertex shader?
hmm, not necessary, i just wanna get the geometry that would create roughly the same figure
for example for a cirlce , we just need the center and the radius and with a simple pi * (r*r) we could resemble the same shape, but for a complex shapes, i dont know what can be done
Like in a script?
yeah
although we can easily figure out the outline using the alpha of each shape, so i think there might be a way
It's probably easier to dilate/inflate the edge pixels with a custom shader.
not sure what you are talking about , could you give me a code example ?
I say easier, but outlines are difficult. This is a good post about it, but you can quickly see how complicated things can get if you want something optimized.
https://bgolus.medium.com/the-quest-for-very-wide-outlines-ba82ed442cd9
But this is particularly for wide outlines. For smaller 1px outlines, there are better approaches.
thank you so much ❤️ , yeah it looks quite expensive but im glad it exists, unfortunately, he didn't share the code but, that is ok for now, i'm still just trying to learn, i have no use case for it yet 🙂
can someone help me reintroduce alpha-clipping shadows back into my shader similar to how shadows in URP lit shader works?
Is it a graph or shader code?
You're using an alpha clip shader and it's not affecting the shadow ?
shader code I'm pastebinning it right now
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
You either need to create your own fragment shader for the ShadowCaster pass, or use the keywords and properties names that it expects.
I think these properties would work
[Toggle(_ALPHATEST_ON)] _AlphaTestToggle ("Alpha Clipping", Float) = 0
_Cutoff ("Alpha Cutoff", Float) = 0.5
Might also be _BaseMap instead of _MainTex
Ah but it's a sprite shader too...
Then yeah, instead of ShadowPassFragment you want to make your own. Use that one as a template, just swap the properites out. https://github.com/Unity-Technologies/Graphics/blob/master/Packages/com.unity.render-pipelines.universal/Shaders/ShadowCasterPass.hlsl
Or just use shadergraph ? 😅
Yeah could be easier
alright I'll take a look at both, thanks!
pretty simple shader graph to get it working, now I'm just curious is there a way to get the cameras current x rotation with a graph node?
Not the rotation value itself, but you can get the "View Direction"
Or the camera forward with the Camera node
is there a way to output node values as numbers?
so I can visualize what their values are?
Not really, but for direction you can output the value as unlit color
I wish there was a way to debug.log in shader 
I do have a "debug value" node in my library though : https://github.com/RemyUnity/sg-node-library/blob/doc/rush/Documentation~/nodes/debug/debug value.png
Outputs a readable text, applied to the specified UVs
ooo that's pretty cool. Sometimes I just wanna see what numbers are as I have a better time grasping them
this outputs any number to a texture?
Not really a texture, as it just outputs a float value. Consider this as a greyscale mask of the text, that you can plug to the base color, or lerp with anything you want for more fancy display
It's important that any values being debugged that way are the same across those pixels though, right?
Yes, of course 😅
Just read in between the garbled pixels to get all the values 🧠
Does someone know how to support single pass stereo rendering for built-in render graph shaders?
I know that URP fixes this but I can't swap to it because it breaks all my materials and UI rendering
A simple shader but it wont update on my material? What do i do?
Shader: Lit Shader Graph
Shader Graphs do not work well on UI canvas set to Screenspace-Overlay. Tends to work better on Screenspace-Camera, possibly with an overlay camera to render it.
set the image to that?
you clicked save asset?
If it doesn't already support it, I doubt there will be a way to handle it in Shader Graph. Could use shader code instead - see https://docs.unity3d.com/Manual/SinglePassInstancing.html
A shit thanks!
I did this but its still invisible in game, did i do it wrong?
well, now it doesn't appear at all
What a shame, there is no way I can implement that from scratch in time and there are barely any shader coding tutorials for full effects
I have it set to screenspace camera and a blank image will appear but the material object still wont
If you changed the Canvas render mode it might be behind walls now since it puts it on a plane infront of the camera, at a default distance of 100. Can adjust the plane distance on the Canvas component but keep it within the near plane.
Or can overlay the UI using another camera which may clear depth. Might be more info here - https://www.cyanilux.com/faq/#sg-ui, (but the implementation varies between pipelines, I only really know URP)
im using URP
when I added another camera it makes everything on the canvas invisible in game but without a camera, objects work
but the material one still wont
@regal stag im not sure why this happens?
What type of graph is it?
idk if this helps
ive had it working before
then legit just stopped working at some point xd
shadergraph? i think
this is the mat the shader is applied to
I meant more like, Unlit Graph vs Sprite Unlit. Sometimes the sprite one works better.
It's in the graph inspector/settings
Unless you're on really old versions, then it depends which "master node" you have
i dont have that open i dont think
i just have inspector occlusion and lighting
oh wait
im stupid
1 sec
yeah its Unlit
@regal stag it is Unlit
oh shit changed it to sprite and it worked
Maybe try the Sprite Unlit, see if that makes it appear
yeah it worked
thanks
why the hell didnt that work
cuz it was working for awhile and then I added some stuff to the UI and it stopped working lol
Yeah I've experienced the same thing in the past. I think it's better in newer versions, but still doesn't have proper support for UI
i think this is unity 2021
2022*
not too sure even tho its the top middle usually
ah 2020
I would like to make it so that everything that intersect with a transparent cube is going to be clipped and I can't get it quite to work...
hey all, I’m new to Shader Graph and I’m trying to create a new transparent material. I’m getting weird artifacts on the rendering which I thought forcing depth write should fix but it doesn’t seem to make a difference. Does anyone know how to solve this issue?
I want the material to ignore itself if it happens to overlap, so for example the tail above should not be visible behind the body
See "Transparent Depth Prepass" heading under : https://www.cyanilux.com/faq/#transparent-sorting
thanks! guess the solution wasn’t as simple as I thought 😅
got it working with the prepass shader, thanks again @regal stag!
What's the difference between view direction and camera direction? (if any?)
I do not actually know, but if I would guess than its that the cameras direction is just literally the cameras forward direction. But the view Direction is the actual direction going out from each pixel, probably calculated with something similar to this cs float3 viewVector = mul(unity_CameraInvProjection, float4((o.screenPos.xy/o.screenPos.w) * 2 - 1, 0, -1)); o.viewVector = mul(unity_CameraToWorld, float4(viewVector,0));
Interesting, I was curious I don't actually have a use for it (yet). always handy to know
i followed the technique as seen in this video from polytoots, but im guessing i cant get the same effect if my textures are so low res
How do you set target shader model in Compute Shaders?
I tried adding #pragma target 4.0 at the very top, but it returns Shader warning in 'test': 'target' : unknown pragma ignored at kernel CSMain at ...
Maybe shader models can't be set in compute shaders? I'm using bitwise operations (leftshift) and I'm afraid it doesn't work properly (didn't test thoroughly tho), in HLSL it is said that these operands are only supported in shader model 4.0 and above...
Hey Everyone, my Water Shader is splitting the object faces, something that I don't want to. Is there any way of keeping the faces together?
I'm trying to learn shaders and using these as a starting point: https://youtu.be/KeOPgH-v-ts?t=631
When I'm working on this section of the video (10:30+), my shader graph shows that the texture should be scrolling downwards but when the shader graph gets applied to the cylinder it doesn't scroll at all, it simply rotates with the cylinder performing its rotation.
To try everything Brilliant has to offer—free—for a full 30 days, visit https://brilliant.org/GabrielAguiarProd/ The first 200 of you will get 20% off Brilliant’s annual premium subscription.
Now you can create intriguing portals for your Games!
00:00 Intro
01:32 VFX Graph - Plane and Cylinder
03:56 Blender - Modeling Cylinder
06:05 Shader Gra...
I've closely looked at the shader graphs in the video and mine seem to match:
If I apply this transform to go from World space to object space, how do I get the world space from the object space?
rayOrigin = mul(unity_WorldToObject, float4(rayOrigin.xyz, 1));
I've tried float3 worldPos = mul(unity_ObjectToWorld, float4(samplePos.xyz, 1)); but that doesn't seem to have the desired effect
so, im trying to use legacy shaders > particles > multiply, material on a UI element but im getting
"doesn't have _Stencil property" warning, can I disregard or is there a UI mat that has multiply somewhere ?
when a game is playing on the monitor attached to the UHD 770, why is GPU usage near zero?
Unless you specifically make the .exe run on the iGPU, it will use the dedicated GPU for heavy loads
how can it do that when it's the i gpu electric connector that's drawing the screen?
Google 'windows run game on iGPU' @dense bane
no, if you know tell me
No lmao
I don't know all the exact settings names, and couldn't bother.
I'm helping out in free time, so just take the advice
Guys, I'm trying to create a custom shader using shader graph, in every other nodes, things are going fine, but scene color node is not outputting the output adding a screenshot for reference
am I doing something wrong here?
that is how you transform it back to object space tho
if the faces are all connected this shouldn't be possible
Does it show something if you don't have anything plugged into the uv's?
@lunar valley , in that case I don't see a noticable change in the object
@everyone, a small suggestion, shall we just keep one topic specific discussion in corresponding threads? it will make the section less clumsier
Could be UV problem
Check the value on the Material itself. If you saved the graph after creating the property, before changing the default value, it would have defaulted as 0
Could also try adding a Saturate node before the power. Maybe there's negative values messing with it?
"google it up" is not an advise, you're wasting my time pretending to know and most likely don't understand the question
As far as I know some motherboards allow output from the dedicated GPU via the iGPU. There can be a bios option, which if there is named differently per board vendor and not all boards have it.
If that's not found I don't think there is a way to force a display to run on iGPU
So the best solution is to force certain applications to use the iGPU if that's what you want, which is easy to do
So I've ran into an issue using for loops in compute shaders and I'm not sure this issue is solvable or not. Basically if you assign a value to a global variable inside a nested for loop, and then attempt to read it outside of the for loop after breaking, it's like the variable becomes unusable and either returns garbage data or resets the GPU.
Are nested for loops that bad in compute shaders?
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
This code always returns 0
Have you tried passing the variable in as inout, maybe as a temporary local instead of the global variable?
I've never modified global variables like this, so I don't know if it's supposed to work
i have not tried using inout, not sure how it works exactly. I've tried setting the variables as locals though but it doesn't seem to matter. right now i'm trying to write to a RWTexture2D instead but it doesn't seem to work either? The issue is that I can't carry a value out from the for loop to even return anything
it seems if you use a for loop as the outer loop and a while loop as the inner loop it might work. nested for loop is no go.
nope nvm, it worked in the test project but bluescreened my computer in my main project :)
hi, some one know wy my scan lines effect is not mixing with the scene?
Scene Color node would require the Opaque Texture to be enabled on the URP asset.
But what type of graph is this? How is it being applied to the screen?
If it's the new fullscreen graph you probably want the URP Sample Buffer node instead
where do i activate that asset?
What pipeline are you using
is a overlay effect, like vhs
URP
How are you applying the shader to the screen
UI Image? Blit feature? Fullscreen graph + feature?
Cyanilux
/
URP_BlitRenderFeature
by this tutorial https://www.youtube.com/watch?v=3Ccu3UtiSdw
Now you can easily add a Retro feeling to your game with this cool Shader Graph and Render Feature combination. With a few Post-Processing effects on top and that's it you got yourself a CRT / Old TV feeling. Enjoy!
Pixel Art Tutorial: https://youtu.be/JZDlCuIpq9I
Cyan Blit Render Feature: https://github.com/Cyanilux/URP_BlitRenderFeature
00:...
Right, then you want to create a Texture2D property named MainTex and sample that to obtain the source texture.
I honestly don't have much knowledge on the subject, but if you can help me its fine
Blackboard window in shader graph, click +, Texture2D, name it "MainTex".
Drag property into graph, connect to Sample Texture 2D node. Use that instead of Scene Color.
that node can't connect to the lerp
Connect it to a Sample Texture 2D node first
wow thank's, i could never have found the solution by myself thank you¡¡
how do I correcy these two errors?
What is cosTheta quivalent of?
there's no node for that
dot product maybe 🤔
Did I make a mistake in reproducing that formula? getting broken pink
neat
dont know why it tried to sample a texture but neat
following tutorials online is frustrating when the writer makes leaps of knowledge
http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-16-shadow-mapping/
they say 'use this' but they dont say HOW or WHERE to use it
frustrated by assumed knowledge that renders the entire tutorial worthless and useless 🔥
How would I go about identifying if that is the issue and how would I fix it if it is so?
I tried testing it on a different model (the built in sphere) since that is basically what the shader graph preview shows and the result is not the same as the shader graph preview.
thats kinda cool
yeah I saw it do this unprompted in an earlier question and asked it 'draw an ascii diagram of the shadergraph nodes' to get that
neat
neat 📸
still hammering away at this shadow map thing that ive been doing for like two weeks now
its SO close to being perfect
but the shadow cascade thing is ruining the entire effect
what is this supposed to be? It looks really cool
I need to 'solve' whatever tf the shadow cascades are causing this to fuck up but so far its been nothing but dead ends
its sampling the main light direction and shadow positions, comparing distance between the light's position on the mesh vs. the fragment position to aproximate mesh distance for transmission
essentially this
where the light hits the mesh, distance from the fragment to the spot is zero
the further the fragment is from where the light hits the mesh in the direction of the main light, the larger the value
the problem is something to do with shadow cascades however that causes this
I can't seem to find the exact point the problem occurs to correct it
I cant even properly debug it to tell you exactly WHAT the problem is, all I have is the fucked up output as shown
the problem occurs directly on the edges of the shadow cascades however so I am assuming its something to do with them
this
this is me scrubbing the shadow cascade value
That’s wack
Yeah, I need to solve it to not do this
but I cvan't figure it out 🤔
I have very little hope of solving it myself, I am not a shader wizard, I am a monkey with a typewriter
I have just been posting it constantly everywhere in hopes someone smarter than me will see and take pity on me, because thusfar all my own attempts to solve have failed
dont really have any prospects for a sollution otherwise, ive exhausted every doccumentation or other implimentation I could find
I think this is responsible in some way?
because shadow depth shows that exact weird wtf banding
but again, I have no answers or ability to debug this, all I have are outputs that I have zero comprehension why they do what they do
and attempts to trace it back to a source cause have been little more than flailing blind in a cave
do you see any obvious cause of my problem here?
I have been hammering at this for weeks and I cannot stress enough how I really really really need help with this
literally all I have is perseverance 🔥
the cutoffs happen at such exact regular intervals
maybe there is some way to subtract them out using some kind of space coordinate and a Fraction node
but Im too stupid to figure out how to do that
or where to even begin
yeah im starting to get distressed again
every single day for weeks now its wake up -> work on this stupid fucking POS shader -> fail to make any kind of progress -> turn to every forum I can find to beg for help -> radio silence -> collosal meltdown -> repeat
i have literally no other choice or option but to repeat the same thing every single day hoping something different will happen
and so far failed every single day, every single second of every single hour
and its utterly destroying my mental health to fail this frequently
I am begging you to help me solve this
I am well aware that desperation is utterly repulsive
but I have no other recourse
im well aware of how incredibly worthless and pathetic this makes me
im going into crisis now so here's the relvent assets while I give up as the worthless POS not deserving of help that I am
if someone could tell me what I have to say or do to deserve to get some help that'd be great
thanks
its so close to done
but no one will help me bridge the last 1%
and its so incredibly frustrating and I dont know why I don't deserve help, can't get any help
I'm sorry i should shut up im obviously losing my shit
I'm looking at your problem and there's nothing that screams out to me as wrong. That's why I'm not responding; because I have no notes.
thats fair and appreciated, being acknowledged that I am even talking or exist is appreciated
its so hard to be a developer and mentally insane
its so incredibly frustrating to be the person who drops everything the instant anyone asks me for help, but I don't get the same treatment in kind
I know that isnt a reasonable expectation, that its an unhealthy standard, but its so fucking frustrating to be raised on promises of 'work hard and youll succeed' when its all bullshit and nepotism
My guess was that the shadow depths were being encoded differently for each cascade and needed additional processing to extract the correct values, but looking at the URP source, I can't see that as the case.
i noticed the problem only really 'happens' after the values get adjusted
when its just the raw data it looks right
but I need a looooooong range of 0 to 1
and when you do that, the cascade lines show up
all of my attempts to rescale the values before or after the magic black box that just makes it go havent resolved this problem
I'm guessing it's not an option for you to just disable shadow cascades?
its not, that makes the entire rest of the project look super bad
maybe there is some way to only sample one cascade instead of all of them??
What does a HLSL matrix (say, int4x3) translate to in C#? I'm using a RWStructuredBuffer with a struct that contains such matrix, and I'm wondering what kind of field the equivalent would be in the C# equivalent of the struct.
but to my knowledge doing that wouldnt work beyond the first cascade since there'd be no data
For example:
HLSL:
struct MyStruct {
int3x4 matrix;
};
C#:
struct MyStruct {
??? matrix;
}
This is needed because I'm passing data from a compute shader to the CPU through a RWStructuredBuffer<T> with T being MyStruct. Both the C# script and the compute shader need to have the same struct with the same elements, each element having the same stride -> they have to be virtually identical types, no tricks with arrays or so.
im goign to step out for a walk for my own sanity's sake, back in a bit
The Unity.Mathematics package has a int3x4 type you can use.
Ooo sounds good, is it literally the same as a collection of exactly 12 floats ordered the way a 3x4 matrix would be?
If it has some other auxiliary fields or so it won't work
Where int3 looks like this:
https://github.com/Unity-Technologies/Unity.Mathematics/blob/master/src/Unity.Mathematics/int3.gen.cs
I've read a bit, it seems Unity.Mathematics is exactly made to work with HLSL, or generally shader languages
And that certainly looks like the way an int3x4 would be structure in HLSL too
Hm, I'll use it, but pretty annoying if I have another possible space to debug if that doesn't actually work
Thanks for the info ^^
Hey, i think i saw an option to automatically fix shaders for URP in the project, but now i can't find that anymore. Somebody knows where that is, or was it maybe part of some plugin i had?
It depends on your URP version, but there should be a Window > Rendering > Render Pipeline Converter.
many thanks ❤️
Any clue what might be causing these artifacts to appear when I render a sprite to a render texture using a compute shader? It still works fine because the alpha on the non-character pixels are all 0 but if possible I'd like to avoid these stretched out pixels around the object.
All my render textures are created with these settings
preRenderTexture = new RenderTexture((int)robRend.sprite.rect.width, (int)robRend.sprite.rect.height, 1, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
preRenderTexture.enableRandomWrite = true;
preRenderTexture.filterMode = FilterMode.Point;
preRenderTexture.wrapMode = TextureWrapMode.Clamp;
preRenderTexture.Create();
Unity does this on purpose, to avoid artifacts when rendering the sprite with transparency like edges darkening when using bilinear filtering
hmmm. alright. maybe i'll leave it in. i was going to use the textures as masks for shadowcasting but since the alpha is generally accurate i'll just use that channel.
Guess it depends what the result is used for. If you don't want the colours stretching out you can just multiply by RGB by the alpha channel.
does anyone know what these errors are or how to solve them
the lines and words its referencing dont exist:
"SurfaceDescription" doesnt exist anywhere
You're missing some semicolons
oh yeah 🤔 there are none
Btw posted in #1099329453106143242
thats what I get for blindly trusting in gpt
looking at that now
yeah
in my experience if your expecting good results from GPT you need to really guide it
and know the fundamentals of what your asking it to do (not saying you dont know)
question based on your reply a few days ago... how come the gamma/linear setting effects my fragment shader, but not things in my scene, like my unlit rainbow gradient texture on a plane? and if I wanna stay in linear mode, how do I keep this same more saturated look that gamma mode offers?
because your unlit rayinbow gradient is unlit
if you want to stay in linear mode you can simply convert from linear to gamma inside of the shader, instead for you entire project. You can look up the formula for it this also goes the other way around
yeah
Power of 2.2 gives a different output. Or did you mean to say the formula is something different?
hi , could someone explain to me what does it mean to do return a float.xxx
for exxample
fixed4 frag(v2f i) : SV_Target
{
float f = 0.1;
return float4(f.xxx,1);
}
when its ok to do f.xxx and when f.rgb ?
does f.xxx = float3(0.1,0.1.0.1); ?
also what is f.xyz or f.zyx ? they didnt work in my example but i saw some functions that has them so I guess , in certain conditions , they're acceptable, but what is it ?
im still learning shaders and almost everywhere ppl are using those symbols without any explanations, when I tried to google it , other things poped out.
how do I google it ? what does it called?
It's called swizzling. Basically, it returns a new numerical variable constructed from the components of the accessed variable.
f.xxx would be the same as float3(f.x, f.x, f.x)
f.zyx == float3(f.z, f.y, f.x)
This would work if f had 3 components, i.e. if it was a float3
Swizzling is very common in shader code. It's like the hlsl sugar.
ohhh! , i see now
so if float3 f = float3(1,2,3); i can use f.xyz or f.zyx , but i wasnt able to use it in the above example because f was a single float , even though i was able to do f.xxx thanks ❤️ ❤️ ❤️
Any help for this?
Hi, I've been struggling to delete this node from a shader graph but I can't
it happened because I was copying a graph from another project and even tho I copied the subgraph first it just messed up completely
I've been trying everything and when I simply delete it this happens:
as you can see, there is no * to save anything but if I try pressing save this happens:
I even tried finding a method with this name and ID in the generated code but there is no such thing:
I would really appreciate your help because I am quite in a hurry
one more thing that I forgot to mention is the following error when deleting the node:
I also get problems like this in 2022, it's very annoying. If you aren't already could try updating to the newest possible minor version in the hope it's fixed.
If the validation is the problem, you could try creating a Sub Graph Asset, then edit the GUID in the meta file to match that string. Then try deleting the node when the validation is fixed and delete the SubGraph asset after.
I just created a new shader and pasted everything, thanks either way!
I'd probably apply a 9-sliced sprite texture if it's a UI component.
!code
📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
Hi, I created this simple shader which keeps the border size as it is irrespective of object scale. it is working fine in 3d objects but not in the UI elements such as panel.
any help. thanks in advance.
oh what if I want without texture.
Could likely pass the rectangle bounds/size into the shader through the material - either manually or via a C# script.
ok. so it is not possible to do it inside the shader itself.
Cool. thanks
Is there a way to have the top half of the skybox UVs flat on the UV space instead of having the entire sphere cut on the side?
What do you mean by "cut on the side"?
instead of having the UVs wrapping like the first image, I would like to have them like on the second image (only the top half section matters, so the bottom can be mirrored from the top)
or how can I go from world space position to the second image UV space
You can get the result in Blender by viewing the mesh from above in ortho view and doing UV > Project from view (bounds) operation
You can also project UVs in a similar way in a shader
In SG you can project a texture from above in object space with UVs like this
The offset is for centering a texture in one by one unit scale
Thanks @grizzled bolt that helps a lot 👍
I have an EditorWindow that helps me build houses from prefabs such as floors, walls etc (not in game view, but scene view). I want certain parts of my floor / wall prefabs to be red instead of their usual material (only parts, not the entire thing) if they are behind some collider such as the terrain collider for example.
How would I achieve this? I imagine with shaders. Could anyone point me in the right direction on what to read up on? Thanks (rendering pipeline is URP)
You can use a shader with ZTest Greater to only render fragments/pixels if their depth is higher than the depth buffer.
There's a similar example in the docs using the RenderObjects feature overrides - https://docs.unity3d.com/Packages/com.unity.render-pipelines.universal@16.0/manual/containers/how-to-custom-effect-render-objects.html
Those would make it appear behind all opaque objects though, not just specific ones like terrain. If that's important you'd probably have to render the terrain depth into a custom buffer, sample it in the shader with ZTest Always, compare depth and clip/discard pixels manually.
thank you so so much for the incredibly detailed answer.
Hi! I need help with this shader I got from Unity asset store https://assetstore.unity.com/packages/vfx/shaders/glam-glitter-shaders-20921. My game required less than 1M texture size and without any PNG file this shader keep giving me texture size exceed error. I would really appreciate if anyone help me solve this issue.
i am going slightly insane: if i name a property _EmissionPower and have a float variable named _EmissionPower, it's always zero. if i name it anything else, it works fine.
this is for a VRChat avatar, so it's the core renderer in 2019.4. baffled!
my workaround is to not name it that, but...it's very strange
the compiled code seems identical, save for the different name
Maybe there's a script somewhere overriding it's value?
nah, i can set the parameter without it getting overwritten
although, I could still believe an animator is somehow messing it up...
Yeah might be fine on the material but edited through a MaterialPropertyBlock or something
oh, bah, that's what it was 🤦
i guess the animator is using a property block?
thanks :p
Yea I think so
the property used to be very badly named (it was called "emission power" but was actually albedo)
so i fixed that and added an actual emission power property, and... oops!
i just realized that the new albedo color is actually also emission, because I forgot to multiply by the light color...
So I want to replace every grayscale with a set color which I will do by sampling a gradient texture but right now I'm doing it by copy pasting a bunch, there must be a better way right?
The value of the gray is a consisten increase of 2 in HSV if that helps in any way
The better way would be sampling a gradient texture instead as you mentioned, using the greyscale value as a UV coordinate.
Something like this then yes? there's 30 total colors.
It's still 1 at a time though, can I make it go from 1-30 at the same time?
hey,
is it possible to turn shader into an image ?
and i mean a jpg or png formate image
If your shader has an effect on your entire scene you apply the shader to a sphere and place your camera in the sphere, that camera can output to a render texture, then you can use EncodeToPNG
I'll give that a try, thanks ❤️ ❤️
i have another question as well , i asked yesterday but no one replied to it.
if I need to pass an array of floats to a function with length between (1 to 10 items )
I learned that shader only accept fixed array and it doesnt have option for dynamic array.
how do I solve this ?
A - make 10 functions 1 for each possible number of items float arr[1] , ... float arr[2] ..., float arr [10]
B - Make 1 function with the highiest possible number of items 10 and just pass to it empty values for the items we are not using
IMO (B), but remember that everything in shaders is passed BY VALUE. If you do (A), how do you end up deciding on what function to call of the 10 possible functions? That decision logic will PROBABLY be just as expensive if not more than the overhead of the extra bytes passed.
But maybe even better is to assign the values to a global array, if setting them is something you can deal with without multiple threads clobbering stuff.
well, i dont know what global array is but the shader should act differently based on the number of points , so i need to pass the array to a function and it cant be dynamic
But who/where are the values in the array set?
they are input by the user
So set from C#?
Thanks ❤️ ❤️
yes! and then sent to shader via setFloat()
Why pass them at all?
It's a uniform file-scope variable
So before your first function, declare the array, do the sets in C#, and "just use" the values.
You'll probably want another variable to indicate the # of elements.
uniform numFloats;```
(the keyword 'uniform' isn't really necessary.)
ohh , so u think (B) is the way to go then ?
NO I think a uniform is the way to go. That's (C) 😉
So you don't have to pass anything at all to the function.
wow, then i have no idea what you are saying , i still dont know how to inform shader frag about the 1-10 points ?
any chance you could give me an example, ?
i certainly know how to write in c# and lately "c" as well
im learning shader for the first time btw, im a complete noob
Could someone look at this as well please? I can now loop over every gray band and give it it's color individually but idk how to combine them all 🙃
I just gave you an example.
Do this:
uniform numFloats;```
at file-scope inside the pass.
so ```pass {
blah, blah, blah...
uniform float myDataArray[10];
uniform numFloats;
blah, blah, blah
v2f vert() {
v2f o;
...
return o;}
half4 frag(v2f in) {
...
for (i=0; i<numFloats; i++) {
<do something with myDataArray[i]>
}
}```
So when you set that in C# on the material, that material has ONE array of 10 floats, that gets shared across all threads invoked on that shader/material, and all threads get read access to that one array of floats.
The uniform keyword means that the values is/are the same across all thread invocations in that draw call. It is the default for things at file-scope. So it's unnecessary but helps for clarity.
All this assumes that the values are READ-ONLY for the shader. In other words, the shader code isn't changing the array's values in the various running threads.
thank you so much ❤️ ❤️ but unfortunately, as i mentioned , the float values are user input , means the user may modify them on running time
is that a deal breaker for this concept?
Anyone know why my refraction is creating this weird line across the screen? If i rotate the cam it moves with the camera but stays the same length. Turning off refraction is so far my only fix. Even if i put the strength to 0.1 its still there
Hello everyone,
I'm having trouble with a billboard shader that I'm trying to make in Shader Graph
Please take a look at the video.
As you can see, sometimes the render order for the billboards is correct and sometimes it's not.
Here's my Shader Graph
and here's the material
I think the problem has something todo with the how I'm facing the billboards at the camera, and that is somehow causing the wrong render order, but I'm pretty green with shader graph (and shaders in general) so if anyone can point me in the right direction, I'd sure appreciate it
how do I use sprites in shadergraph?
or is there not a way? I'm noticing with some annoyance that it doesn't let you use Sprites from a sprite-sheet as texture inputs in a shadergraph's standard image input
A sprite is an object associating a texture (the sprite atlas) and the sprite image coordinates (offset and size).
You can easilly access the texture in the shader.
If you apply the said shader to a sprite renderer in the scene, the UV will be the sprite coordinates and you can just sample the texture.
how did you make your refraction?
No, shaders are run per frame. You'd set the values per frame. The GPU process runs "between" the user setting the values and the final results of the frame.
I think it's the classic problem with how transparent polygons are rendered, transparents don't write to zbuffer, that's why the zsorting issue.
I think the easiest way to solve this is to use alpha mask with dithering node, but it wont be 'true' transparent though
I think I understand about 40% of what you're saying. While I was following the tutorial I was wondering how the Z-buffer order was determined when you start screwing around with the positions of the faces on a single mesh, it seems the answer is "it's determined incorrectly".
I think you've given me enough to google to muscle through it. Thanks!!
Something like this then yes there s 30
can anyone tell me why my shader material suddenly looks like this?. the meshes look fine with different materials
nvm i found it. apparantly i changed the allow material override
Is there a market or contact-place from Unity that I can use to commission shaders?
This usually happens when meshes with overlapping or intersecting surfaces use a transparent shader
The closest thing I know of would be !collab
We do not accept job or collab posts on discord.
Please use the forums:
• Commercial Job Seeking
• Commercial Job Offering
• Non Commercial Collaboration
The Unity Manual mentions that shaders have an appdata and v2f struct, and a vert method, but the shaders that are generated from the shadergraph have no such sections. If I wanted to add stuff to the aforementioned structs/method in the code generated by shadergraph, where would I have to do so?
The names appdata, v2f and vert are all user-defined. Those names are common for shaders made for the built-in render pipeline, but Unity devs decided to use different naming for scriptable render pipelines. Most commonly, these are:
appdata -> Attributes
v2f -> Varyings
vert -> <Something>Vertex
frag -> <Something>Fragment
I don't know what names Shader Graph uses, but it's probably similar to what I just posted.
How can I solve this problem?
I cant delete the keyword in my code, or even change it
It means a shader pass contains two #pragma shader_feature _ DEBUG_DISPLAY lines
Debug question: Is there a way to anchor a shader to the game main camera but not to the scene camera?
Use case would be to inspect a shader effect from another perspective without altering how the shader is rendering it (since its based on the camera)
afaik this camera node treats the scene viewport like the camera just as much as game treats main camera as the camera
I am thinking the brute force-est way would be to completely rebuild the shader to replace the view point with a position and direction, but something tells me there's more to the camera than that and probably wouldnt work even if I got it working right
These particular ones I think you could pass as properties externally
Other stuff like view direction would have to be transformed in some way to be relative to the specific camera
I assume that would quickly get complex because a lot of the parts of the render pipeline weren't meant to be separated from the specific camera they're being rendered from, which the scene camera is
Yeah thats what I was thinking, getting real complex for something I only want for debug purposes 🤔 Not worth the effort
I agree not worth for just testing purposes
I assume trying to do it for shadow cascades or SSAO or other such complex features would get incredibly difficult
is there an easy way to do a full screen shader in URP yet or do you still need to use a custom renderer?
Still need to use a renderer feature. But 2022.2+ includes a Fullscreen Pass Renderer Feature, and Fullscreen Graph type which works with it.
awesome thanks, I'll take a look at that!
Hello there, is there a way to use the stencil buffer in shadergraph? I need it to modify a sprite mask material and give it a color on the spot it is masking
An example, here is my sprite mask, and it is showing a sprite that is behind the black sprite; what I want to do is being able to read that hole information in a shadergraph and add my own color for example to that spot, instead of modifying the gray sprite color itself
Or maybe is there a way to use a sprite renderer instead to work as a sprite mask? like rendering one part and ignoring another?
I need to do the same affect as a mask but the result is always drawing the full sprite instead of drawing the half that is inside
ShaderGraph doesn't do stencils but if you're in URP there are overrides on the RenderObjects feature which could help?
What's wrong with using the grey sprite exactly? Do you need different colours for each spot?
I tried messing with Render features there but I was not getting the result I needed, I was probably doing it wrong but It got really messy with very random results
Yeah, exactly and I also need to use an actual sprite there instead of a mask to add more detail
the masked result does not give me a detailed interior as using a sprite (second image shows the sprite)
Now that you mentioned it, shouldn't render objects feature work on 2D? I mean, the sorting layer of sprites should override that making it almost unusable right?
Then I would render all of the black geometry to the stencil buffer, then render the splats/cracks on top testing against it
How would I do this?
I currently have the ground with visible sprite mask
and the interior (gray part) as visible inside mask
I don't work in 2D so not sure how it works with RenderObjects. But I imagine it would move the objects out of the regular transparent queue so any sprites rendered using it would always be behind or ontop
I see, same here, I am not very familiar with 2D so I did not expect to find these issues
So sprites would be considered as transparent instead of opaque?
Maybe by putting the Mask components on the ground instead, and have the splat SpriteRenderers be Visible Inside Mask?
Afaik yeah
Why didn't I think about this earlier? It did work LMAO
thank you so much for your time
hi i am pretty new to unity and i'm looking at tutorials on how to make shaders in vfx shadergraph, but i'm assuming shadergraph stuff is extremely resource intensive for mobile. So i was wondering, is the proper workflow for mobile supposed to be to create the shader, then bake that into a texture for the model? if so how do i do it, and is it possible to bake animations created using nodes in shader graph too
I think you are confusing some things my friend you don't bake shaders into textures. Shaders is the whole reason why you can see things on your monitor, you cannot have no shader. So shaders won't make your performance worse shaders are required
Whether a shader/graph is expensive depends greatly on what calculations it's doing
You can bake the shader result to a texture (e.g. https://github.com/Cyanilux/BakeShader) but you'd still need another shader to render that. Could be cheaper, but that won't work if anything is animated.
Also always good to actually test/profile before trying to optimise.
right, but i'm not supposed to have a bunch of different shaders in a scene right? so i should have everything rendered with one shader? the shader i am using currently mostly just changes colors.
well more importantly i want to know if its possible to grab the animation i generated using noise
Having less shaders does means objects can batch together which can help with performance, but you don't need to limit yourself to just one
i see, yea but these are mostly for spell effects so i can see there being a lot of them if i don't figure out a proper workflow early on
I assume it's vertex displacement? That's not really the same as a cpu-side skinned animation so no. Shaders run on the gpu, transform vertices and paint pixels directly to the screen (or whatever render target is bound)
im not sure if its vertex displacement but i assume it is, the effect was made using time, noise, sine, and vertex? nodes
If it's connected to the Position port then yes.
There still may be ways to make that displacement cheaper. Like if it's using Simple/Gradient Noise nodes those are procedural (created via math), but a seamless noise texture (sampled with Sample Texture 2D LOD node) could be cheaper on mobile.
its connected to that
so theres no way to like, "record" the animation somehow and iono turn that into a static animation thats not attached to the shader? not sure if im wording my question properly >.<
No it's not possible, and even if you could replicate the vertex displacement on the cpu it would definitely be slower. Shaders/gpu does things in parallel so is great at doing calculations like this.
Vertex animation exists, and is usually encoded into textures that can be sampled in a shader. But that's usually reserved for complicated simulations that couldn't reasonably be done in real-time, like liquid simulations.
wait, so do you mean that the animations that are created using shaders on the fly takes less system resources than say a static animation that i imported in from blender? or am i overthinking it and something simple like pieces of the mesh moving around via noise nodes, doesn't take enough resources for me to need to consider this at all
I don't know much about cpu-side animation. But that runs on armature/bones, then the vertices are weighted/skinned to those. It's hard to compare as those are for a different use-case where the animations can't be procedural/math based and need specific keyframes. I would say you're overthinking things.
ok so basically i cant turn the shader generated animation into a keyframe animation
Is it logical to implement mesh generation for my voxel game in compute shader instead of C# script?
Greedy mesh generation to combine same adjacent voxels
set vertices, triangles (faces), uvs for each voxel segment
// loop
for (var j = 0; j < 4; j++)
{
_uvs.Add(faceDef.HasTexture ? uv : Vector2.zero);
_tileData.Add(tileData);
var pos = (Vector3)faceData.Vertices[j];
var vertex = pos.Multiply(voxelSize) + (Vector3)chunkRealPosition;
_vertices.Add(vertex);
var color = faceDef.HasColor ? faceDef.Color : Color.white;
color.a = voxel.AlphaValue;
_colors.Add(color);
}
for (var j = 0; j < 6; j++)
{
_triangles.Add(currentVertexIndex + IndexOrderList[j]);
}
anyway thx for the help, im really new to this still so trying to figure out the best way to do things
I'm working on a (relatively) simple stencil setup that basically has a camera filtered with a stencil setup in front of it. The stencil "cuts" out the player character and renders it to a RenderTexture – so that only the character is in the final render texture image. The stencil successfully cuts out objects, but I realized now, if an object is either (1) in front of or (2) intersecting the player character, the data of the character is cutoff. Is there any easy solution to this problem? (sorry im a bit of a noob at stencilling)
It's a SubGraph. At a guess, I'd say it's multiplying the Scroll property by the Time output from the Time node.
If you only want the player to appear in the render texture, why not put the player on a specific layer and remove all other layers from the camera's culling mask?
😔 restrictions of the platform i am designing it for, it's custom in-game content rather than an independent creation
have access to stencils but not camera layers
And what does this mean?😅
hey,
how to right an array of floats in shader ?
somefloats[4]("description ...", Float) = 0 ?
In the material property block you cant
oh! , then how could I pass an array from c# to the shader then ?
Should be a float array api?
For the material class
Not on my PC atm
But if there isnt one the closest you'll get would be vectors or matricies
@prime shale thanks , but I couldnt get it to work
im trying to have a float array in shader to be able to use it later using setglobalvariable , and I read online that i need to mention the array in shader
_floatArray("Array", float) = (1.0, 2.0, 3.0, 1.0, 1.0, 2.0, 3.0, 1.0, 1.0, 2.0)
the problem is if the array is bigger than 4 it fails
can't do arrays in the material property block
ahh
if you want to pass an array of floats it will have to be through c#
by material property block I mean the inspector values that you get exposed to you, when you mess with the material that has your shader
and how would I mention it in the frag function for example ?
float _X[250];
or float _x[]
then in C# it'd be material.SetFloatArray("_x", xFloatArray);
ohh !! and if i wrote on c# Material.SetFloatArray("_X", array); <--- that would be the value of _X in shader?
you'd be setting the values of the float array _X in the shader yes
Thank you ❤️
SubShader
{
UsePass "ShaderPath/FORWARD"
UsePass "ShaderPath/DEFERRED"
Tags {"RenderType"="Opaque" }
CGPROGRAM
#pragma target 3.0
#pragma surface surf Standard fullforwardshadows addshadow
#include "UnityCG.cginc"
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
UNITY_INSTANCING_BUFFER_START(Props)
UNITY_INSTANCING_BUFFER_END(Props)
void surf (Input IN, inout SurfaceOutputStandard o)
{
fixed4 p = tex2D (_Pupil, IN.uv_Pupil);
clip((c.a)-0.2); //Clip the previous passes?
}
ENDCG
}
FallBack "Diffuse"
How do I make it so that I can discard pixels from a previous pass? Like, if the previous shader is opaque, but this shader, using the previous shader's pass, is trying to discard pixels from the previous passes? How do I do that?
Trying to do a dissolve effect.
how could i do this kinda thing?
I kinda want to try a shader where it renders triangles like this depending on their proximity to a vertex
This is how I want it to look
Is there any way to render a cube like this?
if i have 10 enemies with same material one of die and active a dissolve effect for one who die, so the alive enemy will also change with dissolve effect how to fix
anyone ?? how to manage material saperatly
Hello! In UE I used this curved world shader for an art piece, and I'm looking to convert it to Unity. For some reason I can't seem to get it to work though, and I'm not exactly sure why? I made sure to adjust the values to what they'd be with Unity's measurement system. Would anyone be able to tell me what I've done wrong?
I think barycentric coordinates is exactly what you are looking for https://www.google.com/url?sa=t&source=web&rct=j&url=https://catlikecoding.com/unity/tutorials/advanced-rendering/flat-and-wireframe-shading/Flat-and-Wireframe-Shading.pdf&ved=2ahUKEwiK_dGy9PH-AhWMjYsKHURzCNMQFnoECCkQAQ&usg=AOvVaw1l6A8rH8Hgy-Ap2AqvKsrv
I'm creating an outline for selected GameObjects. So far all tutorials use one of the following methods:
- a material attached to the renderer that bases the outline on vertices positions (like the one in the screenshot)
- a post-process that creates an outline with a constant width around all the renderers from the particular layer
Have you encountered any other notable approaches for this topic?
@fervent kiln Change this to the correct on in the prefab
You can't, each pass renders the model again separately. You'd need to copy the pass code itself and add the dissolve/clip line in.
(Though I think it'll be possible when Block Shaders are a thing as they're meant to be more modular)
I found a way by using GrabPass
Hmm okay, I assume grabbing the screen before any of the passes are rendered and the last pass layers that ontop. Not ideal for overdraw, but works I guess.
Looks like parallax occlusion mapping, might be something to look into. Shader Graph should have a node for it.
There's also a "shell texturing" technique which could do something similar.
Set properties by using renderer.material. That'll create a material instance/clone at runtime. https://docs.unity3d.com/ScriptReference/Renderer-material.html
he could have maybe also instanced a bunch of "grass" blades which took the color that the texture on the grass currently has below them. Or it might also be just that he moved the vertecies of the mesh noise or texture
Or for Built-in RP, set a MaterialPropertyBlock on the renderer.
Instancing grass blades is also an option, but wouldn't say that's what is in the image specifically. And vertex displacement would require the plane mesh to have a lot of vertices, or also have tessellation hull/domain shaders.
The Position port values need to be in Object space, so you should use a Transform node at the end to go from World to Object.
If it helps, this is the setup I've used for world bending (is a subgraph that would be connected to the Position port)
There's a bunch of outline techniques listed here : https://alexanderameye.github.io/notes/rendering-outlines/
Thanks for the link, I will take a look.
yeah, I mean could have been a lot, hell he might have raymarched that plane
Ty! I tried that, and it didn't seem to give better results. I also initially tried following a tutorial before attempting to convert the UE version, but I couldn't manage to figure out how to get the functionality I was after. I'd like to offset the falloff of the curve. I tried adjusting the power, but whenever I tried with the version in this screenshot it didn't work. I've attached a graph of the type of falloff offset I mean!
I tried doing quite a bit of other things (Like clamping before the power), but it keeps seeming to break, and I'm also not super sure how to debug in shadergraph just yet.
Does someone tried to make a blur (kawase, gaussian) effect for Fullscreen mode (compatibile with Render Features) in Shader Graph?
I don't know how to get a Texel Size and Tiling (to recreate the effect found on the internet) properties in Fullscreen mode from URP Sample Buffer.
Screenshot is from the shader graph I try to recreate, they use MainTex.
Should be able to do the same thing, but with BlitTexture (reference _BlitTexture)
Should I use it when I got URP Sample Buffer node? Hah
Well, that node doesn't allow access to the texel size, so makes it a bit more difficult. But I guess you could still use a Custom Function to try to obtain it.
I found texel size function (reply from March 2023)
Technically it is meant to be defined as a TEXTURE2D_X to work with XR. Defining it as a regular Texture2D would likely break that, so using the URP Sample Buffer or defining the texture in a custom function would be better.
Yeah that might work
That could likely just be a Vector2 property
ok, let's give it a shot 😄
Ty I tried that and it didn t seem to
The effect is not striking, but it works (Tiling set to 0.1 value; it doesn't work for 1 value; smaller value increases offseting).
It's not as good as in the showcase I found
As he descirbes it's a box blur algorithm btw
From the description & sticky notes in the graph it looks like it's used with a renderer feature that downsamples the screen target before applying the box blur
Ahh, so the main texture used in the graph is the downsampled version of the screen?
Yea
I found this in sticky notes now 😄
Hmm, I need to think how I can do this like him. Should I use some RTHandle with scale parameter to Blit into? (In Renderer Feature)
Btw I also found that SSAO built-in Render Feature is using a blurring effect (Bilateral, Gaussian, Kawase), so probably I will also copy-paste this into my Renderer Feature
Hello, my shader graph auto generates stars in the background using high scale simple noise and a very low step node. For me it works well but when I sent my friends the same build I played on, the stars were all weird and repeating, anyone know how to fix this?
Seed is a random Float from -100 to 100
Normal stars
Their stars
I'd understand if Simple Noise was just broken but why does it work for me on the same build?
Is it possible to have 2 shaders on one sprite and then use a mask to reveal the other shader?
Maybe something like using 2 subshaders in one shader?
not sure.. I know something like this is possible in 3D, why not just using one shader
I'm making a pixel art game but just adding black to pixel art for shadows is a big no-go, so I want to make my own shadows by masking correct colors instead
ok, why not do that in one shader?
That's the plan
ok
This is not particularly helpful...
well I don't know how I should help you if you answer all of your question yourself
and I am also not quite sure what you want to do and what making own shadows by masking correct colors should mean
Have a question
So I want to learn how to dissolve an object by passing another over it
Something like this
Don't know how to even start. Does the object getting scaled hold the shader material? Does each object getting dissolved hold the shader material? How they affect each other? Help
For the time being I'll just look into Boolean
Ah, it took a while, but I finally tried it and I realized I was apparently just using the built in pipeline and the shader was incompatible with it 🤦♂️Well thanks anyway, maybe ill have a use for it in future projects :) ill have to find some other way now if there is one
You can do that with a stencil shader
I'll look up stencil shader
Or u can give a run down on what it does
Oh saw a video. Thanks
Ok I get how stencil works but what about the glow at the edge
Also it from what I can see it stops rendering places the cube is touching or renders only places the cube is touching. What is I want to use something like a plane and render it hasn't passed yet not rendering places it has passed till it passes it again
One sec
Something like this. So I can just slide the glowy plane pass all the robot for them not to render then aas I slide them back they start showing. Can stencil also do that?
God that was hard to read but hope u understand my question
The shader/material on the spheres is likely taking the box's world->object/local transformation matrix in (passed manually through Shader.SetGlobalMatrix or material.SetMatrix)
The world space positions in the shader are transformed into the boxes coordinate system using that, they're then relative to that box. The glow and clipping would be based on whether those coordinates are smaller than -1 or greater than 1. Glow would be something similar... probably absolute(posRelativeToBox)-1 and min (maybe max) to combine the axis. Bit off the top of my head so calculations could be wrong.
Could also look into a box signed distance field which would be similar. https://www.youtube.com/watch?v=62-pRVZuS5c
If you just want a plane, should be able to subtract a position that lies on the plane then dot product with it's normal iirc. If the plane is aligned to a specific axis (i.e. X axis), can just do step(planePosX, worldPos.x)
Hello, does anyone know why I have all OToon materials transparent?
That was hard to understand
I'll first watch the video then try again
Have a rough idea of what you mean. I'm going to have to try it when the light comes on for both the box and the plane
I understand the plane own better though that seams easier plus it's what I wanted to go for anyways. It'll be similar to how I do normal dissolve from what I can tell
I am trying to come up with a shader graph that takes in a texture and is able to seperate all the colors so I can recolor the texture using this graph, I can't really think of a way to do it that is not limited to the RGB channels though. does anyone have any information on this?
What kind of texture is the input? Is it like pixel-art?
it's for character models
RGB channels would be plenty for hair colors but when I want to customize the color of an outfit I would only be able to use 3 colors
If there's a single colour per face could make a palette texture, and UV map each section of the model to it. Then generate the palette at runtime in a C# script from a bunch of colour fields.
if Unity would load I could make a quick shader of what I want to expand on
I want to be able to do this but with more colors
if it's not possible I will simply have to make sure all textures only contain 3 colors sadly
Does the input texture always have full brightness colours? Like, this works with darker versions of the red/green/blue, is that important?
yea that is important
though that gives me an idea, is it possible to take a texture and a color as input, and then have it output a grayscale result of everything in that color?
I guess that would conflict with other colors though
One method I've used in the past is something like this. Specific red values are used as UV coordinates to sample a horizontal palette. That doesn't really allow for darkening the colours, but since the green channel is unused you could maybe store a brightness in that.. 
that sounds like what I want. but how would I do that? xD I'm not sure I even understand this version
what is the palette_space texture?
also does this still allow me to use alpha for transparency?
It's a 5x1 texture with pixels containing the colours
Yeah the regular texture can still have an alpha channel
The red values in the first texture are the x positions of those pixels (normalised in the 0-1 range, since that's what UVs use)
Would be values of 0/255, 63.8/255, 127.5/255, 191.3/255, and 255/255. I explain it a bit more here https://www.cyanilux.com/tutorials/color-swap/#palette-texture
It is somewhat of a complicated setup, hence why I've only really used it for pixel art stuff
so if I were to have a clothing texture with 7 colors that all have different shading,
I have to:
- store the different colors as different shades of red
- store the grayscale in greenscale
- create a texture of 7x1 and input colors into it
but then I'm back at the issue of how I set the colors in that texture from shadergraph
Yep
You don't. But that 7x1 texture could be generated at runtime in C#. Using Texture2D class and colour fields.
Yes you'd use a C# script
I'm not sure how you'd make such a script
I think it could be something like
public Color[] colors;
void Start(){
Texture2D paletteTex = new Texture2D(7, 1, TextureFormat.RGBA32, 0);
paletteTex.SetPixels(colors);
paletteTex.Apply();
}
Then pass the texture to shader. Either using Shader.SetGlobalTexture or material.SetTexture
does this need to be on a Game Object?
Yes
I'll see what I can figure out, thanks alot :D
im getting this weird issue with my shader
i dont see anything wrong with it
it worked before, i didnt change anything
Yo!
I got a problem with character dither dissolve. It supposed to dissolve but it's not. Why?
This used to work. Now it doesn't
Alpha Clipping is disabled on the material
any way to make a water shader like this on URP?
yes
how because I tried a few times and got stuck at trying to get refraction and reflection to coexist
or getting reflections at all
The BoatAttack demo has a PlanarReflections script that you could use - https://github.com/Unity-Technologies/BoatAttack/blob/master/Packages/com.verasl.water-system/Scripts/Rendering/PlanarReflections.cs
Basically uses a second camera flipped across Y axis. Would pass the reflection into _PlanarReflectionTexture property reference. Sample it with Screen Position.
well there are multiple ways, you can get reflections going, there is planar reflection looks very crisp and good but costly, then there is reflection probes, then there is screen space reflections SSR, and then there is raytracing ^^
there is not a single method that is 100% perfect you will just need to choose what you need
planar reflections required having to manually setup a camera and it worked but only for one water body, as another made it be underground, reflections probes look shitty, and ssr stops reflecting things after a certain point
so
yeah as I said, there isn't a perfect solution, most games combine all of the techniques to create their water system, so that it works on most use cases
how do I do ray tracing then?
in urp
Well... I wouldn't know how I would implement a raytracing system into unity while also having rasterization going.. For making raytracing in general you will find a lot online. You essentially want to trace some rays with low resolution and then denoise the shit out of it.
yeah I
hmm
I mean ssr does use raymarching
but
^^^
the best current solution that rasterized has at the moment
is using parallax corrected cubemaps (or reflection probes)
and then ontop of that is SSR
that is the best you'll get unless if you switch to dedicated raytracing
planar reflections would be more what you'd expect, but as you seem to recognize that obviously has the downside of needing to render the game world again, and also that if you have multiple in a scene it would just look wrong
I mean unreal managed to merge it, so theoretically you could do it too ^^
if you should do that is debatable
Can someone help me out with this one? If you need me to send shader code, I can DM you.
did what I wanted thanks a lot cyan. turned out to be easy after trying what u said
I'll have to figure out how to handle the shadow. I'll look into that
I have an issue as well that might be simple. Some of my materials say that
"Material x doesn't have meta pass - maps are taken by name"
U will probably have to wait for cyan to come online I haven't seen that. though curious about it and the fix
Same, I'm not sure why it'd occur. My project has had many breakdowns due to working on a world for VRChat specifically, and I guess things still don't work too well together at all times.
I've had to delete the Library several times by now for randomly broken scripts and shaders to compile.
that sounds like a big problem your tested scripts randomly break?
But this has been recurring even after Library delete.
like after u confirm they work?
Yup, same with shaders
Randomly, I get an error that some texture or another isn't correct, so a shader fails to compile. I delete the library, error is gone, shader works.
the texture library?
U know what? we've typed a lot, repeat the question so he sees it
I'm not sure I have a screenshot, but the console would pop up with a random shader saying that something assigned to a shader is incorrect. It was some UV texture written in code for the shader before, that was gotten from Unity itself.
Either way, that's not the current issue anyway, those can be fixed by the Library folder being deleted
Project rebuilds, it's all fine
The current issue is this ^
Everything seems to be fine, but it'd be a pain to realize that something was actually broken all this time
Using Unity 2019 is definitely a hassle, despite being LTS, specifically most likely because of VRChat's weird integration
Can someone help me out here? I need to find out why this isn't working
Nice. ✨
If it's shader code, should look into replicating the clipping in the ShadowCaster pass. For surface shaders, can use addshadow on the surf pragma to make it generate one.
Afaik the meta pass is only required if you're baking lights. I think this specific error is associated with the Bakery lightmapper?
Even if you try to bake and the materials don't have a meta pass, it'll apparently still try to grab textures by their usual names, as the error mentions. (e.g. _MainTex for albedo). If the result looks fine, probably safe to ignore it.
I would check the Frame Debugger window, to see if both passes are being rendered and in the correct order. (If they aren't, may need to look into adjusting the LightMode or Queue tags). To overlay the fresnel pass ontop, it's likely easiest to make it render after with additive blending
Turns out it's Forward Rendering the blank fresnel sphere, which would be fine if the other pass was even showing up on the other sphere. I have a gut feeling it's being ignored.
Yup, bakery. It doesn't look out of place, just worried I'm not noticing it. But maybe if I'm just worried, there's probably nothing off there anyway.
It straight up ignores the pass I'm telling it to render.
You could also try including a fallback statement to one of the standard shaders if you're hand-writing the shaders.
https://docs.unity3d.com/Manual/SL-Fallback.html
UsePass may also be of interest to "pluck" out a meta pass from a standard shader
https://docs.unity3d.com/2019.3/Documentation/Manual/SL-UsePass.html
any way i could get this type of effect in urp shader graph? theres 8 lights around an object with 0 metallic and 0 roughness on 814W
I'm not quite sure what I am looking at...
you will probably only be able to do this if its per object based
You could store the thickness info somewhere inside vertex data, e.g. by modifying vertex color or normals, but it creates new restrictions.
Perhaps other people here will have better ideas.
I write a custom outline shader pass in hdrp, it looks perfect if I disable the fog. However, after I enable the fog, the outline will disappear. Looks like the fog on top of the outline.
Is there anyone know how to fix it?
Can you schedule the outline AFTER the fog?
The outline looks to be outside of the object itself (external outline, rather than internal outline).
Maybe you could try writing the outline to the depth buffer.
Just rambling.
How can I write it to depth buffer? Do I need to modify the GBuffer pass?
IDK enough about your implementation.
When does the outline happen? While outputting the mesh, or in a separate screen-space pass, or what?
If it's a pass of the mesh, perhaps extruded, just make sure zwrite is on.
It is a pass of the mesh, and the zwrite is also on
Then IDK, it should already be updating the depth buffer. IDK why fog doesn't take that depth of the outline into account.
Maybe it's a fog problem, not a mesh/outline problem per se.
Others may know.
implement your own fog :3
For debugging purposes, you could try to output depth as a color and make sure the depth of the outline is the same color as the edges of the mesh, just to prove to yourself it is writing the proper depth value. You'd do that on both the normal mesh and the outline mesh.
Also I think you can view the depth buffer in unity's editor (Window/Analysis/Rendering Debugger--->map overlay = depth
It's not in the depth.
IDK what you mean. The outline is not in the depth?
If so, it should write to depth.
The shader should have "zwrite on"
https://docs.unity3d.com/Manual/SL-ZWrite.html
But note that things that are closer to the camera than the outline will occlude it.
Also note that fog implementations vary. So objects (let's say mid-way into the scene) can have some depth-based fog occluding them. Your outline could have the same thing, depending on if it is implemented as a post process or done when writing the pixels the first time.
All these things have to work together.
public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
{
CommandBuffer commandBuffer = CommandBufferPool.Get();
commandBuffer.GetTemporaryRT(tempHandler.id, renderingData.cameraData.cameraTargetDescriptor);
commandBuffer.Blit(source, tempHandler.Identifier(), material);
commandBuffer.Blit(tempHandler.Identifier(), source);
commandBuffer.Blit(source, tempHandler.Identifier(), material2);
commandBuffer.Blit(tempHandler.Identifier(), source);
context.ExecuteCommandBuffer(commandBuffer);
CommandBufferPool.Release(commandBuffer);
}```
I am trying to pass the modified depth texture (that i modified with ```commandBuffer.Blit(source, tempHandler.Identifier(), material);```) to material2, how can i do this?
using the _CameraDepthTexture returns the unmodified version
i output SV_DEPTH on the first one
i have no idea if i am completely offtrack or not, i just need to get the depth i modified using material1 and give it as an input to material2
Trying to write a surface shader to apply a color ramp to lit 3D models
Im applying the color ramp in the FinalColor part of the shader
for some reason, when multiple lights are applied to my model, the finalcolor changes unexpectedly
to debug this, im currently setting the color to a fixed value of 0.5, 0.5, 0.5, 1
but the color brightens to pure white when a second light interacts with the model
what causes this?
I see people suggesting to enclose the finalcolor function in #ifndef UNITY_PASS_FORWARDADD, and this kind of solves the issue, but then the additional additive passes just don't have the desired effect, they use normal surface shading
what i need is for the very last final color to use this function, after all of the lights have been added
im pretty sure the issue is that the finalcolors are being combined together with additive blending, can i change the blend mode of the light passes?
The finalcolor modifier is not additively blended, but the Forward Add pass is. The problem here is that the built-in render pipeline in Unity uses additive passes for additional lights in forward rendering. There's no way to change that. Even if you could change the blending mode of the pass, it wouldn't help because the base light pass and additional light passes would still be separate and there would be no way to do a final composite of them like you're trying to do.
You have a few options to get around this.
- Only pixel lights use the Forward Add pass. Vertex lights are performed in the base pass. If you force all lights to be vertex lights (by setting them all to "non-important" or by setting the max pixel light count to 1 in Quality settings), then all the additional lighting calculations will be performed in the base pass and you can calculate your color ramp correctly. The downsides here are you're limited to 4 lights per object and they will be lower quality than pixel lights, but the second problem can be avoided with custom lighting that processes vertex lights as if they are pixel lights.
- Completely avoid Unity's lighting system and make your own, by calculating what lights need to be passed to what objects and processing them in your own shader.
- Don't use the Built-in render pipeline and use something like URP, which doesn't have an ancient forward rendering path and instead does everything in a single pass.
I’ve been avoiding changing pipelines because from what I can tell, shaders aren’t compatible between them and you need to use shader graphs or whatever for the other pipelines
You can write shaders for SRPs, but since they don't yet have a replacement for surface shaders (it's being implement though), they must be vertex/fragment shaders, and so they will have more boilerplate if you want to fully implement lighting. Unlit shaders are, for the most part, compatible between render pipelines.
Well what about multiple passes
Could I calculate the base lighting in one pass and then apply the color clamping to the resulting color
You won't be able to read the pixels from previous passes, so no.
Man that’s annoying
I might try the vertex lighting idea in my case, I’m implementing this for a pixel art styled game so there aren’t often going to be a lot of lights at once
One other thing I was experimenting as a hacky workaround was just subtracting the previous light pass’ color from the current one but that didn’t work as expected either
That should work since the light passes are additive though, right?
You were returning a negative value in the Forward Add pass?
No, at the end of each pass I would store the previous pass color, and subtract that from the current pass
I’ll post the code shortly
That doesn't sound right, because you can't pass information between passes.
Unless you're writing it to a separate texture or buffer object
Outside of the function I had a fixed3 _prevCol, which was assigned to the finalcolor at the end of each lighting pass
And then on additive passes I was subtracting that from the finalcolor
Would _prevCol not persist between those lighting passes?
Well shit, is there no way to do something like that? Store a variable between functions?
Well you're not just talking about a variable. Every pixel needs to store it's own color. So what you're talking about there is a texture.
I should clarify that there is no special relationship between multi-pass shaders and any other shader. Sure, they are each drawn in sequence, and they are each part of the same shader and same renderer, but to the GPU, they are completely different draw calls.
Does that refer to lighting passes too? I’m talking about the additive lighting thing
The GPU doesn't have the same concept of a "multi-pass" shader as Unity does. It's just separate shaders that are drawn right after one another.
Yes, it applies to lighting passes too.
Is there anything you’d personally recommend here? The effect I’m trying to achieve is pretty simple I’m just running into a bunch of annoying technical issues, all I’m trying to do is take the resulting brightness of the lighting and set the color of the pixel to a corresponding value in a color ramp
Since I’m doing the color ramp on the finalcolor function here it’s being basically doubled for every light
The simplest way is probably to do it as a post processing step. Draw everything with normal lighting, and then with a post processing shader, apply the color ramp to each pixel.
The downsides to that are that it isn't as mobile friendly and you can't do per-object color ramps as easily.
Per object would be necessary in my case
It wouldn’t be possible for a second pass to read the color of the lit pixel, would it?
It's possible to pass a RWTexture2D to a material/shader, which you can then read and write to from a shader.
I don't think I've ever seen an implementation that does that, so I'm not certain of the performance you could expect from that, but I'm fairly confident that it works. But it's a relatively recent feature in GPUs, so low-end hardware may not support it, mostly old mobile phones.
You would need to create a RenderTexture in script with the same dimensions as the screen and then bind it globally with Shader.SetGlobalTexture.
Then in the shader, you can define it as a global variable RWTexture2D<float3> _MyTexture; (float3 for RGB), and read and write to it like a two dimensional array:
int2 pixelCoords = // you will have to calculate the pixel screen position;
_MyTexture[pixelCoords] = color.rgb;
// Read from it the same way:
int2 pixelCoords = ...;
float3 prevColor = _MyTexture[pixelCoords];
You will also need to define #pragma target 4.5 to set the minimum shader target version to be able to use this feature.
back at my pc now, i'll post the shader rq
I won't need to see it unless you're expecting me to write the implementation for you. The specifics of the shader doesn't change how this would be implemented into it.
im not expecting that, just figured i'd share so the issue is a little more clear
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
single light
2 lights
since the base color of the ramp isn't black, even parts without any actual light touching them basically double in brightness between each pass
I wish there was an easier solution I could give you, but this is ultimately the limitation of the forward add pass. The solutions I've given you so far are all to avoid the additive pass, because no matter what you do (unless you force vertex lighting), additional lights will always be added with additive blending.
Even if you use the RWTexture2D solution to pass data from the base pass to the additive pass, it will still be pretty hacky because you will need to return a value from the additive pass which when added to the base pass with additive blending, will result in the color you want.
is there something im missing here?
the red and green material both use the same exact shader
The directional light should always be important. Just the additional lights should be vertex lights.
they have the same issue though, they don't light up the green material, only the red one
is there some technical detail im missing about vertex lights or something that could cause that?
Are those submeshes that are part of the same renderer?
I could imagine that being the cause, but I don't know why it wouldn't work. I don't know how Unity handles vertex lighting with submeshes.
i think what i'll do is just make additive light passes reduce the color count of the light instead of applying the color ramp to every pass
at least this way i can draw colored lights a little better
as long as i reduce the color count enough it will avoid the issue of making sprites look super muddy
Im having trouble changing my shader can anyone help me out?
can anyone help me change my shaders on the model
You need to ask an actual question to get actual responses
ok now i just feel like a complete idiot, can someone help me wrap my head around this
trying to make a scrolling reflection texture for a 2D surface
I need to sample a reflection texture based on screen space, but offset that screen space coordinate based on a scrolling speed multiplier
i can't figure out how to increase the speed of the scrolling without scaling the texture im sampling
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;
o.Normal = tex2D (_NormMap, IN.uv_MainTex);
o.Albedo = c.rgb;
o.Alpha = c.a;
fixed4 refl = tex2D(_ReflTex, (IN.screenPos.xy / IN.screenPos.w) * _ReflScroll) * tex2D(_ReflMap, IN.uv_MainTex).a;
o.Albedo += refl;
}
This is what im doing now, i just take the screenPos and multiply it by a scrolling speed
but doing this also scales up the texture im sampling
mathematically, what can i do to multiply the offset without scaling the reflection texture?
Yo, is it possible to render both low quality and high quality things in the same game view? Basically, I have like an overlay that covers the screen. It displays by having a certain script on the main camera which controls a shader that creates this overlay. I want that overlay to be high quality. But then I also have the game itself, and I want that to be really low quality. Is there any way to achieve this?
Currently I have 2 cameras with one having a low quality render texture, but they only work individually, not together.
Basically imagine you are looking at your monitor and are playing a low res game. Your monitor is high quality because ofc it is, its in real life, but the game is low quality because its on your screen.
In my case, the shader is kinda like the look of the monitor, with the edges and overlay and stuff
I'm using the in-built pipeline too so yeah 😐
Idk if that makes sense
Thanks.
Color ramp? Like toon shading? (based on brightness)
yes, to achieve a 'pixel art' downscaling effect on my 3D models, im using a color ramp to limit parts of the model to color ramps based on their brightness
i ended up working something out though
Well, you can render to a low res texture like I think you're doing.
I have NO IDEA what you mean by "Currently I have 2 cameras with one having a low quality render texture, but they only work individually, not together." I mean, cameras stack, so the 2nd camera should render over the first one. If it is high-res for the UI, what isn't working?
Another way would be to render everything normally and do a post processing pass to reduce the screen to a pixelated look. Then apply the UI.
Pixel art based stuff can be tricky.
You might need to do a blit between the two cameras to a higher res render texture used for the 2nd camera.
In this Unity tutorial we find out how to get a convincing low resolution look, like in the game a short hike.
Github Source: https://github.com/Renge-Games/PixelRendererTutorial
Be sure to subscribe to be notified of my future uploads!
Have a request, or you want to make a suggestion? Post it in the comments.
Follow me on Twitter: https://tw...
Wondering if anyone can point me in the right direction here, I don't have much shader knowledge at all, however I'd like to create a shader which takes the lighting of an object and simplifies it into either black or white. If the lighting is below a certain brightness it becomes black and then the opposite is true for white. I'm trying to use shadergraph with URP and am pretty stuck on what the best way to accomplish this would be, any guidance would be appreciated!
Hi all, I was just watching this video, https://www.youtube.com/watch?v=KXykryML824, it looks like it has some sort of pixelated sahder/post processing on top of some basic shapes to create a cool pixel art effect. Does anyone know how to achieve this look? Thanks in advance
For the Brackeys Game Jam, I recreated Ape Out's design, colourful style and smash 'em up combat. In Synthetic you can use a grappling hook-style tentacle to grab enemies and slingshot yourself across the level. Made with Unity :)
// PLAY: https://dawnosaur.itch.io/synthetic
// JOIN THE DISCORD: https://discord.gg/W5vE5WKXYH
COSMOS: https://st...
from some of the comments he mentioned "Pixel Camera", are we looking at the 2D pixel perfect camera and somehow achieve this?
Such effect can be achieved with postprocessing. The solution will differ depending on the rendering pipeline you're using. Here is an example video:
https://www.youtube.com/watch?v=5Jl-40B5mtk
Alternatively you can just reduce the game resolution to some small value via Screen.SetResolution. It's much less flexible, but much simpler and more performant.
Apoyame en:
PATREON ➜ https://www.patreon.com/GameSlave
KO-FI ➜ https://ko-fi.com/gameslave
Más de mi trabajo en:
Instagram ➜ https://www.instagram.com/_dervishh/
Estudio Indie ➜ https://www.theatomiclife.com/
you need to use the Unpack function to properly be able to use a normal map
but thats generally the case, its gonna unpack your normals correctly
can you show me what you are doing
- it would be way easier to debug, if you would output the normal map 2) the normals are still in tangent space
in the fragment part, return it as color so that we can see how it looks like anyway you still will need to transform it to world space your normals
ye, I doubt that your normal map looks like that, does your mesh have uvs?
you want to transform your normal from tangent to world
not object
watch freyas shader video I think in part 2 or 3 she explains how to use normal maps. But if you want a quick explenation using a 3x3 rotation matrix containing the tangent normal and bitangents
Hi, I have this simple shader in URP:
Shader "Custom/MyLit"
{
Properties
{
[Header(Surface options)]
[MainTexture] _ColorMap("Color", 2D) = "white" {}
[MainColor] _ColorTint("Tint", Color) = (1, 1, 1, 1)
}
SubShader
{
Tags { "RenderPipeline" = "UniversalPipeline" }
Pass
{
Name "ForwardLit" // For debugging
Tags { "LightMode" = "UniversalForward" }
HLSLPROGRAM
#pragma vertex Vertex
#pragma fragment Fragment
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
float4 _ColorTint;
TEXTURE2D(_ColorMap);
SAMPLER(sampler_ColorMap);
float4 _ColorMap_ST;
struct Attributes
{
float3 positionOS : POSITION;
float3 normalOS : NORMAL;
float2 uv : TEXCOORD0;
};
struct Interpolators
{
float4 positionCS : SV_POSITION;
float2 uv : TEXCOORD0;
};
Interpolators Vertex(Attributes input)
{
Interpolators output;
VertexPositionInputs posnInputs = GetVertexPositionInputs(input.positionOS);
output.positionCS = posnInputs.positionCS;
output.uv = TRANSFORM_TEX(input.uv, _ColorMap);
return output;
}
float4 Fragment(Interpolators input) : SV_TARGET
{
float2 uv = input.uv;
float4 colorSample = SAMPLE_TEXTURE2D(_ColorMap, sampler_ColorMap, uv);
return colorSample * _ColorTint;
}
ENDHLSL
}
}
}
And my problem is that I cant see mesh that have this shader assigned, its completely invisible
Newer versions of URP have "Depth Priming" on the Universal Renderer. The shader needs to have a DepthOnly pass (and DepthNormals if using SSAO as well) to be able to prime the depth buffer correctly. e.g. https://github.com/Cyanilux/URP_ShaderCodeTemplates/blob/main/URP_Unlit%2BTemplate.shader
Could instead disable the depth priming, which will make the object visible, but it still may not appear in the Depth Texture / Scene Depth node.
Do I have to have this whole DepthOnly Pass?
I pasted following pass:
Pass {
Name "DepthOnly"
Tags { "LightMode"="DepthOnly" }
ColorMask 0
ZWrite On
ZTest LEqual
HLSLPROGRAM
#pragma vertex DepthOnlyVertex
#pragma fragment DepthOnlyFragment
// Material Keywords
#pragma shader_feature _ALPHATEST_ON
#pragma shader_feature _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
// GPU Instancing
#pragma multi_compile_instancing
// #pragma multi_compile _ DOTS_INSTANCING_ON
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/CommonMaterial.hlsl"
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/SurfaceInput.hlsl"
#include "Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl"
ENDHLSL
}
But now I have a weird error:
Shader error in 'Custom/MyLit': unrecognized identifier 'real' at URP/Library/PackageCache/com.unity.render-pipelines.core@12.1.7/ShaderLibrary/CommonMaterial.hlsl(29) (on d3d11)
Also see the HLSLINCLUDE section in my example - that gets included in all passes. It has the Core.hlsl include which should fix that error.
You may also want to set up the UnityPerMaterial cbuffer. You would want to put any shader properties excluding textures (i.e. _ColorTint, _ColorMap_ST) inside that so that the shader supports the SRP Batcher.
(It needs to be the same in all passes, hence putting it in HLSLINCLUDE is more convenient than copy-pasting it)
I have a problem that a material changes its color depending on the world position turning magenta
and it only happens in the build
Do I have to have _BaseMap and _BaseColor? Arent these names just variables, so I cant have whatever name I want?
I am asking cuz Ive got this error:
Shader error in 'Custom/MyLit': undeclared identifier '_BaseMap_ST' at URP/Library/PackageCache/com.unity.render-pipelines.universal@12.1.7/Shaders/DepthOnlyPass.hlsl(27) (on d3d11)
Those are defined in the Properties block in my example yes. The UnityPerMaterial cbuffer needs to match that. You don't have those so can remove them, but you'd want to move the float4 _ColorTint; and float4 _ColorMap_ST; declarations from the Forward pass into there.
What shader is that material using?
the URP lit shader
Hmm, well haven't seen this before. Could be related to baked lighting perhaps?
@regal stag Thats my current code
And thats the error:
Shader error in 'Custom/MyLit': undeclared identifier '_BaseMap_ST' at URP/Library/PackageCache/com.unity.render-pipelines.universal@12.1.7/Shaders/DepthOnlyPass.hlsl(27) (on d3d11)
Any renderer features that could be affecting it? Not too sure what else to suggest.
I'd maybe test it in a new project. If it happens there still you may want to report it as a bug and try other versions. 🤷
Oh right, DepthOnlyPass.hlsl is expecting that texture to exist, along with _BaseColor and _Cutoff. So you either need to have those properties, or make your own DepthOnlyPass.hlsl (can copy and edit it - https://github.com/Unity-Technologies/Graphics/blob/master/Packages/com.unity.render-pipelines.universal/Shaders/DepthOnlyPass.hlsl). Then change your shader to include your version rather than the urp package one.
I imagine it's easier to just rename your properties to the expected names though, like in the example
_BaseMap ("Example Texture", 2D) = "white" {}
_BaseColor ("Example Colour", Color) = (0, 0.66, 0.73, 1)
[Toggle(_ALPHATEST_ON)] _AlphaTestToggle ("Alpha Clipping", Float) = 0
_Cutoff ("Alpha Cutoff", Float) = 0.5
Alright I renamed them:
[Header(Surface options)]
[MainTexture] _BaseMap ("Texture", 2D) = "white" {}
[MainColor] _BaseColor ("Color", Color) = (0, 0.66, 0.73, 1)
_Cutoff ("Alpha Cutoff", Float) = 0.5
and I dont have any errors right now, but still I cant see my mesh :<
Oh I added the DepthNormals as well, which you mentioned before, it is visible now. Too bad I have no idea what is already going on in my shader
@regal stag Thanx for help anyways :>
I tried changing a bunch of render features and it work thx very much 🤙
This is a very basic question, you should start with a youtube video about materials in unity rather than wait for an answer here
ok
Is it possible to create an instance renderer that doesnt take a full matrix but instead a buffer of 2d positions? (Using a custom shader offcourse.)
If yes, does anyone have an example in code of this, I can only find how to do it with full 4x4 matrices and not using custom data
Thanks guys
you would need to issue a draw call using Graphics.DrawMeshInstancedIndirect and then bind your buffer with instance data to the instance material.
Im trying to use a consume buffer in a compute shader but it doesnt matter what I do the vaule consumed is always 0. What am I missing? The docs https://docs.unity3d.com/ScriptReference/ComputeBufferType.Append.html also say that I should use the append type
hlsl code:
ConsumeStructuredBuffer<int> consumeValue;
RWStructuredBuffer<int> appendValue;
[numthreads(1,1,1)]
void test (uint3 id : SV_DispatchThreadID)
{
appendValue[id.x] = (consumeValue.Consume());
}
c# code
ComputeBuffer append = new ComputeBuffer(10, sizeof(int), ComputeBufferType.Structured);
ComputeBuffer consume = new ComputeBuffer(10, sizeof(int), ComputeBufferType.Append);
append.SetCounterValue(0);
consume.SetCounterValue(0);
consume.SetData(new int[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
vectorFieldShader.SetBuffer(0, "appendValue", append);
vectorFieldShader.SetBuffer(0, "consumeValue", consume);
vectorFieldShader.Dispatch(0, 10, 1, 1);
int[] intArray = new int[10];
append.GetData(intArray);
int[] intArray2 = new int[10];
consume.GetData(intArray2);
I haven't used consume buffers before, but wouldn't it make sense to set its counter to 10 initially, since it's being consumed?
Trying to write a shader to scroll a ‘reflection’ image across a surface based on the position of the camera, right now I’m doing this by directly passing the camera’s position to the shader via a script, is there a more elegant way to accomplish that?
The world position of the camera is exposed by Unity through the _WorldSpaceCameraPos global variable.
You can see all the Unity shader variables here:
https://docs.unity3d.com/Manual/SL-UnityShaderVariables.html
Oh sweet
I’ve been looking for a page like that, didn’t know what to search to find it
i made a vertex color blending shader in standard pipeline. can i easily convert it to use in urp or do i need to make one from scratch?
for referance, this is what it looks like now
Did you do it with .shader code ? With surface shaders ?
If yes, it is not easy to convert, and you will have to make from scratch. Preferably with shadergraph.
i made it with shadergraph
Then good news : just add URP as shader target in the graph settings 😄
this didnt seem to help though. or do you mean something different?
Wait ... you said that you made the shader for the standard (built in) pipeline. But it's not there as target. I don't get it.
i changed it already
it originally said built in
its also giving me these errors
You are sampling a lot of textures ?
Try to share sampler states between the sample nodes to avoid exceeding the allowed number of samplers
i have a bunch of unconnected nodes from earlier versions in my shader. could those be in the way?
No, if they don't end up connected to the output stack, they are not compiled
from what is connected, i have 4 textures. each with a normal and heightmap connected to a triplanar node
If I'm not wrong, you have 12 connected sample texture nodes to the output ?
yes
here an example of 1 texture, i have 4 of these
Unity will also add samplers automatically for lightmaps and stuff, that's probably why you hit the limit
Like I mentioned, try to add some sampler object and share them between the sample texture nodes
ive never heard of sampler states. what are those?
Descriptor strucs for sampling. With pixel interpolation mode, and wrap mode
Connects to the Sampler(SS) inputs
you are a legend, my textures show up now
do i need a sampler state for each triplanar node or should i connect all of them to 1 sampler state?
I think you can connected them all to the same one
You normally always want wrap-repeat for triplanar, and pixel or linear interpolation depends on the art style but will probably be the same for all the textures
I wonder how feasible or possible it might be to implement more types of texture filtering
Like the 3-point texture filtering of N64
Not "so hard", if you know the logic, and then wrap this in a "Sample Tex2D N64" subgraph or custom function
not sure if its connected or a urp thing, but my wireframe keeps showing even if not selected. looked fine in game though
That's the mesh collider
oh yeah youre right, i couldnt see it in built in though without disabling the mesh itself
@brisk condor do you know any good free light cookies? I dont have unity assets set up for purchase yet
oops should be in #archived-lighting sorry
Oh so sorry lolol, did you meant to ping someone else?
No worrieess
Has anyone here worked with water before on Unity...
I did recently, using shaders, but i'm of the opinion that there could be more additions to this to make it better.
So, please it you have any idea, kindly share it with me. Thanks
why are the ripples so fast is this some artistic thing or? in any case it would be easier to see the water if it wasn't jittering so much
in any case I don't think your water is actually displacing your mesh
is there any way I could use noise textures for Parallax Mapping in shader graph?
like using voronoi as a displacement map rather than a texture2d
You can replace a texture sampler with noise, yes
How would I go about it? i'm trying to use the float output as a sort of heightmap
Not with the Parallax Mapping node, but you can replicate what it does. See ParallaxMapping (and ParallaxOffset1Step) functions : https://github.com/Unity-Technologies/Graphics/blob/master/Packages/com.unity.render-pipelines.core/ShaderLibrary/ParallaxMapping.hlsl
(result is just the offset, so would be added to UV node)
thank you! unfortunately I know next to nothing about hlsl
I assume i'd make a custom node using this hlsl file as a base?
You could create a custom function that includes that file and calls the ParallaxOffset1Step function.
But it might also be easier to just replicate it in nodes.
Is float2 uv like the equivalent of like float uv[2] (in C++/#?
like is it a vector with 2 entries
just trying to read this properly, not familliar with hlsl like at all
@minor remnant Here's the Parallax Mapping replicated in nodes.